Compute AABB on area addition.

This commit is contained in:
Nolan Darilek 2021-06-30 11:16:57 -05:00
parent 1da536d274
commit 4749a09c5b

View File

@ -205,20 +205,21 @@ fn add_map_colliders(mut commands: Commands, maps: Query<(Entity, &Map), Added<M
} }
} }
for room in &map.rooms { for room in &map.rooms {
let shape =
ColliderShape::cuboid((room.width() / 2) as f32, (room.height() / 2) as f32);
let position = Vec2::new(room.center().x(), room.center().y()).into();
commands commands
.spawn_bundle(ColliderBundle { .spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor, collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid( shape: shape.clone(),
(room.width() / 2) as f32,
(room.height() / 2) as f32,
),
flags: ActiveEvents::INTERSECTION_EVENTS.into(), flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default() ..Default::default()
}) })
.insert(ColliderParent { .insert(ColliderParent {
handle: map_entity.handle(), handle: map_entity.handle(),
pos_wrt_parent: Vec2::new(room.center().x(), room.center().y()).into(), pos_wrt_parent: position,
}) })
.insert(shape.compute_aabb(&position))
.insert(AreaTag); .insert(AreaTag);
} }
} }