Realise footstep sounds with the help of Raycast

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By HasMInarchist

I have seen that it is possible to implement the sound of walking using raycast. However, I can’t come up with an implementation. Maybe there is a super mind among the forum residents who knows how to do this.

:bust_in_silhouette: Reply From: godot_dev_

Here are a couple ideas:

  • The only way I can imagine a raycast being used for footstep sounds is if a player can only hear things in front of their character (I suppose you could have multiple raycasts in various directions). The raycast would be point away from the character’s face/camera, and any time an object collides with the raycast you could play foot step sounds. This assumes the collision masks and layers have been setup so that only footstep emitting objects can be detected by the raycast.
  • There may be another or better way for implementing footstep sounds, but an idea that comes to mind is a more flexible solution that instead uses a collision area instead of a raycast. That way, you can have radius around the player (a sphere/circle or some similar collision shape) and when a body enters you do the following:
  • Find the distance from the footstep emitting object to the player
  • Linearly interpolate the volume of the footsteps based on the distance.

Outside the collision area footsteps won’t be heard.

  • The proposed ideas may not be optimal and they don’t consider the stereo nature of footstep sounds

Sounds like something working. I will try. merci

HasMInarchist | 2023-06-01 05:56