Move new area initialization to existing collider initialization system.
This commit is contained in:
parent
0b37adb797
commit
80f163f65f
32
src/map.rs
32
src/map.rs
|
@ -209,6 +209,23 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
|
|||
}
|
||||
}
|
||||
}
|
||||
for room in &map.rooms {
|
||||
commands
|
||||
.spawn_bundle(ColliderBundle {
|
||||
collider_type: ColliderType::Sensor,
|
||||
shape: ColliderShape::cuboid(
|
||||
(room.width() / 2) as f32,
|
||||
(room.height() / 2) as f32,
|
||||
),
|
||||
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(ColliderParent {
|
||||
handle: rigid_body_entity.handle(),
|
||||
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
|
||||
})
|
||||
.insert(AreaTag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,21 +348,6 @@ fn add_areas(mut commands: Commands, query: Query<(Entity, &Map), (Added<Map>, W
|
|||
for (entity, map) in query.iter() {
|
||||
let mut v = vec![];
|
||||
for room in &map.rooms {
|
||||
commands
|
||||
.spawn_bundle(ColliderBundle {
|
||||
collider_type: ColliderType::Sensor,
|
||||
shape: ColliderShape::cuboid(
|
||||
(room.width() / 2) as f32,
|
||||
(room.height() / 2) as f32,
|
||||
),
|
||||
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
|
||||
..Default::default()
|
||||
})
|
||||
.insert(ColliderParent {
|
||||
handle: entity.handle(),
|
||||
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(),
|
||||
})
|
||||
.insert(AreaTag);
|
||||
v.push(Area {
|
||||
rect: *room,
|
||||
description: None,
|
||||
|
|
Loading…
Reference in New Issue
Block a user