Make colliders children of the map.

This commit is contained in:
Nolan Darilek 2021-08-12 13:20:00 -05:00
parent 22abe7462e
commit 00458f1835

View File

@ -216,18 +216,15 @@ fn spawn_colliders(
let id = commands
.spawn_bundle(ColliderBundle {
shape: ColliderShape::cuboid(0.5, 0.5),
position: Vec2::new(x as f32 + 0.5, y as f32 + 0.5).into(),
..Default::default()
})
.insert(ColliderParent {
handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(x as f32 + 0.5, y as f32 + 0.5)
.into(),
})
.insert(MapObstruction)
.id();
if tile.blocks_visibility() {
commands.entity(id).insert(BlocksVisibility::default());
}
commands.entity(map_entity).push_children(&[id]);
}
}
}
@ -314,17 +311,15 @@ fn spawn_colliders(
let id = commands
.spawn_bundle(ColliderBundle {
shape: ColliderShape::cuboid(half_width, half_height),
position: Vec2::new(x, y).into(),
..Default::default()
})
.insert(ColliderParent {
handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(x, y).into(),
})
.insert(MapObstruction)
.id();
if map.at(x as usize, y as usize).blocks_visibility() {
commands.entity(id).insert(BlocksVisibility::default());
}
commands.entity(map_entity).push_children(&[id]);
bottom_left = None;
bottom_right = None;
}
@ -337,19 +332,18 @@ fn spawn_colliders(
(room.height() / 2) as f32 + 0.5,
);
let position = Vec2::new(room.center().x() + 0.5, room.center().y() + 0.5).into();
commands
let id = commands
.spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: shape.clone(),
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
position,
..Default::default()
})
.insert(ColliderParent {
handle: map_entity.handle(),
pos_wrt_parent: position,
})
.insert(shape.compute_aabb(&position))
.insert(Area);
.insert(Area)
.id();
commands.entity(map_entity).push_children(&[id]);
}
}
}
@ -418,20 +412,18 @@ fn spawn_portal_colliders(
for (map_entity, spawn_colliders) in map.iter() {
if **spawn_colliders {
for (portal_entity, coordinates) in portals.iter() {
let position = Vec2::new(coordinates.x() + 0.5, coordinates.y() + 0.5).into();
commands
.entity(portal_entity)
.insert_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid(0.5, 0.5),
position,
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default()
})
.insert(ColliderPositionSync::Discrete)
.insert(ColliderParent {
handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(coordinates.x() + 0.5, coordinates.y() + 0.5)
.into(),
});
.insert(ColliderPositionSync::Discrete);
commands.entity(map_entity).push_children(&[portal_entity]);
}
}
}