play collision sound only on start of collision

This commit is contained in:
yuni 2024-03-31 05:13:21 +02:00
parent 852dd79657
commit 0662f88fdd

View file

@ -561,13 +561,13 @@ pub fn handle_chat_scripts(
} }
fn handle_collisions( fn handle_collisions(
mut collision_event_reader: EventReader<Collision>, mut collision_event_reader: EventReader<CollisionStarted>,
mut ew_sfx: EventWriter<audio::PlaySfxEvent>, mut ew_sfx: EventWriter<audio::PlaySfxEvent>,
q_player: Query<Entity, With<PlayerCamera>>, q_player: Query<Entity, With<PlayerCamera>>,
) { ) {
if let Ok(player) = q_player.get_single() { if let Ok(player) = q_player.get_single() {
for Collision(contacts) in collision_event_reader.read() { for CollisionStarted(entity1, entity2) in collision_event_reader.read() {
if contacts.entity1 == player || contacts.entity2 == player { if *entity1 == player || *entity2 == player {
ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash)); ew_sfx.send(audio::PlaySfxEvent(audio::Sfx::Crash));
} }
} }