map: use collisionlayers

master
Astro 9 months ago
parent 1985db2d17
commit 06954b38ea
  1. 12
      src/map.rs

@ -265,6 +265,10 @@ fn add_island(
let grass_mesh = meshes.add(Mesh::from(grass_box));
children.spawn()
.insert(RigidBody::Static)
.insert(CollisionLayers::none()
.with_group(Layer::Map)
.with_masks(&[Layer::Player])
)
.insert(CollisionShape::Cuboid {
border_radius: None,
half_extends: ground.half_extends(),
@ -304,6 +308,10 @@ fn add_bridge(
})
.insert(bridge)
.insert(RigidBody::Static)
.insert(CollisionLayers::none()
.with_group(Layer::Map)
.with_masks(&[Layer::Player])
)
.insert(CollisionShape::Cuboid {
border_radius: None,
half_extends: ground.half_extends(),
@ -320,10 +328,12 @@ pub fn collide(mut events: EventReader<CollisionEvent>, mut contacted: Query<&mu
.iter()
// We care about when the entities "start" to collide
.filter_map(|event| {
let (entity_1, _entity_2) = event.rigid_body_entities();
let (entity_1, entity_2) = event.rigid_body_entities();
let (layers_1, layers_2) = event.collision_layers();
if ! is_map(layers_1) && is_map(layers_2) {
Some((event, entity_1))
} else if is_map(layers_1) && ! is_map(layers_2) {
Some((event, entity_2))
} else {
None
}

Loading…
Cancel
Save