You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Although bevy's audio story isn't great at the moment I've looked into a simple way to incorporate them into riverbed (and other projects)
E.g. for footsteps a simple system could look like this:
pubstructAudioPlugin;implPluginforAudioPlugin{fnbuild(&self,app:&mut bevy::prelude::App){
app.add_systems(Update, footsteps);}}fnfootsteps(mutfootsteps:Local<Option<Entity>>,mutlast_pos:Local<GlobalTransform>,mutcmd:Commands,ass:Res<AssetServer>,q_realm:Query<&Realm,With<PlayerControlled>>,q_player:Query<&GlobalTransform,With<FpsCam>>,q_playback:Query<&PlaybackSettings>,world:Res<Blocks>,){letOk(realm) = q_realm.get_single()else{bevy::log::warn!("no realm");return;};letOk(transform) = q_player.get_single()else{bevy::log::warn!("no player camera");return;};letSome(below) = world.raycast(*realm, transform.translation(), transform.down(),2.0)else{bevy::log::debug!("nothing below!");return;};if last_pos.translation() == transform.translation(){return;}*last_pos = transform.clone();let entity = *footsteps.get_or_insert(cmd.spawn_empty().id());if q_playback.get(entity).is_ok(){
bevy::log::warn!("Still playing a sound");return;}letSome(source) = (match world.get_block_safe(below.pos){Block::GrassBlock => {letmut rng = rand::thread_rng();let random_number = rng.gen_range(1..=4);Some(format!("sounds/Footsteps Sound FX Pack/OGG/Footsteps_Grass_{:02}.ogg",
random_number
))}Block::Dirt => {letmut rng = rand::thread_rng();let random_number = rng.gen_range(1..=4);Some(format!("sounds/Footsteps Sound FX Pack/OGG/Footsteps_Dirt_{:02}.ogg",
random_number
))}Block::Air => None,
other => {
bevy::log::warn!("Footsteps for {other:?} not implemented");None}})else{
return;};
cmd.entity(entity).insert(AudioBundle{source: ass.load(source),settings:PlaybackSettings{// After the sound has played, this component will be removedmode:PlaybackMode::Remove,
..default()},});}
If you're interested in this, I am open to give back - the main point is just that we have to find assets that we can bundle. I bought some on itch.io for personal use.
Anyway, what do you think?
~ Tom
The text was updated successfully, but these errors were encountered:
since 2 systems already need the info of which block the player is stepping on (footstep system would make 3) I'll put this info in a component and will compute it at the start of the Update cycle
I want this to be asset driven, footsteps sound files will be named after the block they're associated with (we probably can reuse the concept of "block family" from Add more elaborate block breaking #11 here) and these assets will be parsed into a bevy Resource that will know which sound to play based on which block we're on :)
I'm not too worried about getting the sounds in this stage of development (I can record placeholder sounds) but if you got MIT licensed assets I'll gladly include them 👍
Hey!
Adding some audio goes a long way for immersion.
There is multiple facets to this.
Although
bevy
's audio story isn't great at the moment I've looked into a simple way to incorporate them intoriverbed
(and other projects)E.g. for footsteps a simple system could look like this:
If you're interested in this, I am open to give back - the main point is just that we have to find assets that we can bundle. I bought some on itch.io for personal use.
Anyway, what do you think?
~ Tom
The text was updated successfully, but these errors were encountered: