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 {
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
.spawn_bundle(ColliderBundle {
collider_type: ColliderType::Sensor,
shape: ColliderShape::cuboid(
(room.width() / 2) as f32,
(room.height() / 2) as f32,
),
shape: shape.clone(),
flags: ActiveEvents::INTERSECTION_EVENTS.into(),
..Default::default()
})
.insert(ColliderParent {
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);
}
}