Enable collision sensing for bodyless entities
Some checks failed
Basic checks / Basic build-and-test supertask (push) Has been cancelled

Rapier expects to have a RigidBody attached to the entity, but I do not.

I'm not going to make one, either, because the objects in a game of
Asteroids don't need collision handling the way most games do. I just
need to know if two objects have started overlapping.

According to this: https://rapier.rs/docs/user_guides/bevy_plugin/colliders#collision-groups-and-solver-groups
only one of the two objects involved needs to have the ActiveEvents and
ActiveCollisionTypes components attached, so I've placed them on the
player ship.
This commit is contained in:
2025-08-06 15:17:55 -05:00
parent d4ceaa6312
commit ab5f489450

View File

@@ -47,6 +47,8 @@ impl Plugin for AsteroidPlugin {
wrap_entities, wrap_entities,
asteroids::tick_asteroid_manager, asteroids::tick_asteroid_manager,
asteroids::spawn_asteroid.after(asteroids::tick_asteroid_manager), asteroids::spawn_asteroid.after(asteroids::tick_asteroid_manager),
// TODO: Remove debug printing
debug_collision_event_printer,
) )
.run_if(in_state(GameState::Playing)), .run_if(in_state(GameState::Playing)),
) )
@@ -60,6 +62,12 @@ impl Plugin for AsteroidPlugin {
} }
} }
fn debug_collision_event_printer(mut collision_events: EventReader<CollisionEvent>) {
for event in collision_events.read() {
dbg!(event);
}
}
#[derive(Clone, Debug, Eq, Hash, PartialEq, States)] #[derive(Clone, Debug, Eq, Hash, PartialEq, States)]
pub enum GameState { pub enum GameState {
TitleScreen, // Program is started. Present title screen and await user start TitleScreen, // Program is started. Present title screen and await user start
@@ -185,6 +193,8 @@ fn spawn_player(mut commands: Commands, game_assets: Res<GameAssets>) {
.spawn(( .spawn((
Collider::ball(0.7), Collider::ball(0.7),
Sensor, Sensor,
ActiveEvents::COLLISION_EVENTS,
ActiveCollisionTypes::STATIC_STATIC,
Ship, Ship,
Wrapping, Wrapping,
Position(Vec2::default()), Position(Vec2::default()),