[SOLVED] Landing sound after a jump


I am working on a game in which there is an opportunity to jump. When a player lands, I want to reproduce the sound of a fall. I tried to use the contact event for collisions, but it sometimes does not work or works late. Tell me, please, how to do it correctly? Thanks.

It’s odd for that it’s working late. It’s possible that you many contacts are triggered when you land so it’s trying to play the same sound effect over and over causing a ‘delay’.

I would write to the console.log every time you attempt to trigger the sound effect to check.

I just recently coded the logic for this on a FPS game I’m developing, you can see it working:

What I do is simply raycast down and define a bool to check if the player is grounded or not, then when you jump you set the variable to ‘false’, and in the raycast check if it was false, then play the sound and set the variable to ‘true’ again.

Works 100% of the times.

The entity of the player has a rigid body component and a collision. The player also has a mass. When falling, he jumps up a little and then lands back. You are most likely right that many calls occur upon landing and the game engine does not have time to process them all. To solve this problem, I need to set the restitution parameter to zero in the settings of the physics engine?

Thanks for the advice, but in my project that will not work correctly, because I have a third-person shooter in which jumping is one of the main mechanics. If I do a raycast, it will only work when there is a surface under the player. If the player lands on the edge, the sound event will not work, because the beam will not hit the surface.

I solved the problem as follows. I set the restitution parameter to zero, add variable that stores the state of the ability of the jump and used the event collisionstart, which works one time and causes the sound to play.

1 Like

Haha yeah, the rigidbody restitution was the problem!