Footsteps audio syncing?

I am quite new to blender game engine and am designing the audio for a wee game. I just wondered how people would go about getting footsteps sounds to trigger each time the player animation takes a step?

I made a game in Unity engine and did it but attaching a collider to the players foot which triggers a sound effect to play when it collides with the ground mesh. Different surfaces would also trigger different sounds. Would you do it like this or link it to the animation?

If this would involve any scripting, feel free to give me some examples. I have done a bit of scripting in C, C# and Javascript so, although I haven’t used Python, could probably understand it eventually. Thanks.

You could parent an empty to the foot bone and move the empty to the bottom of the foot and then set a collision sensor for each type of sound you would like to be played, then set properties to each type of ground like “groundwood” or “groundmetal” and set the the collision sensor to the corresponding property and sound.

I’d use a ray, rather than collision- that way you can get the specific polygon hit, figure out what material is applied to that polygon, and play a sound according to that. You’d need python, and a library of sounds linked to material names. Python is quite simple (especially if you’ve got C experience… it’s pretty much just a higher level, more grammatical C)
unfortunately I don’t have the time to write up an actual example.

You don’t need collision. You even shouldn’t use it for such things, as computing collisions takes a long time compared to other methods and are not precise (it won’t work on uneven ground).

This is a better method:
Assign the frame of the Action Actuator to a Property
Add a Property “reset” (set to true)
Add a property sensor to this property and set it to “greater” -framenumber of step- and a sensor “reset = true”
Use this to trigger the sound and write false to “reset”
Use a property sensor “framenumber < -startframe-1-” to set “reset” to true again

performance is better than collisions and it is more precise.
You may use a collision-sensor to get the material of the ground, that decides if you use a “wood” or a “metal” etc. sound.

or using code:

def triggersound(cont)
  myFrame = 7 #set this to the frame where the foot hits the ground
  if cont.actuator["walkanimation"].frame &gt; myFrame and cont.owner["reset"] == True:
    cont.owner["reset"] = False
  elif cont.actuator["walkanimation"].frame &lt; 2 and cont.owner["reset"] == False: #assuming startframe = 1
    cont.owner["reset"] = True

All of you guys are now my friends :slight_smile: Thanks for the speedy replies. Will ask another question here if I get stuck. Should be okay though.