generated from 2ndbeam/bevy-template
feat!: Got rid of UpdateShapes component
- update_collider_shapes now filters by Changed<Transform>
This commit is contained in:
parent
8f667f08c6
commit
9d0ae295ee
2 changed files with 6 additions and 26 deletions
23
src/lib.rs
23
src/lib.rs
|
|
@ -130,29 +130,12 @@ impl Collider {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Component, Debug)]
|
||||
/// Add this component on entities, which have their [`Transform`] updated.
|
||||
/// Used for [`update_collider_shapes`] system
|
||||
pub struct UpdateShapes;
|
||||
|
||||
/// Update collider shapes to match new [`Transform`]
|
||||
pub fn update_collider_shapes(
|
||||
mut commands: Commands,
|
||||
colliders: Query<(&mut Collider, &Transform, Entity), Added<UpdateShapes>>,
|
||||
colliders: Query<(&mut Collider, &Transform), Changed<Transform>>,
|
||||
) {
|
||||
for (mut collider, transform, entity) in colliders {
|
||||
for (mut collider, transform) in colliders {
|
||||
collider.update_shapes_position(&transform.translation.xy());
|
||||
commands.entity(entity).remove::<UpdateShapes>();
|
||||
}
|
||||
}
|
||||
|
||||
/// Detect new colliders and automatically insert [`UpdateShapes`]
|
||||
pub fn detect_colliders(
|
||||
mut commands: Commands,
|
||||
query: Query<Entity, Added<Collider>>,
|
||||
) {
|
||||
for entity in query {
|
||||
commands.entity(entity).insert(UpdateShapes);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -189,6 +172,6 @@ pub struct CollisionPlugin;
|
|||
|
||||
impl Plugin for CollisionPlugin {
|
||||
fn build(&self, app: &mut App) {
|
||||
app.add_systems(PostUpdate, (detect_colliders, update_collider_shapes, check_for_collisions).chain());
|
||||
app.add_systems(PostUpdate, (update_collider_shapes, check_for_collisions).chain());
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue