playMaker

Author Topic: Adding footstep sound and particle effect  (Read 10751 times)

tbelgrave

  • Playmaker Newbie
  • *
  • Posts: 42
    • Ispyr Inc
Adding footstep sound and particle effect
« on: October 21, 2012, 06:46:35 AM »
Hiya, me again. This time on adding footstep sounds and particle effects (dust e.t.c) when the player feet collide with ground.

Problem
Trying to figure out an accurate way to play sounds/dust effects when the player walks/runs around. I got it to work somewhat, but when the character runs the trouble begins.

What I've tried
- I currently have L/RFoot Nulls setup in the rig that I can use as locators for the effects. I started with the footstep sound by adding scripts from the Unity 2D/3D platform tutorials with no joy.
- I wanted to use PM for everything so I tried using a Trigger Event on the null (with an audiosource attached) that checks if it has contact with the ground, this works but is somewhat finicky which is fine for now, but when the player begins to run, the trigger event can't keep up and doesn't fire.
- I've also tried detecting collisions with rigid bodies with no luck
- I've tried the Get Game Object Speed action and checked with a float compare to send off events based on the proximity of the null to the ground with wild effects because the resulting floats are too small.

Once the above is solved, I think adding dust F/X would be similar.

Any help/tips/ideas would be most welcomed!


thx!
« Last Edit: October 21, 2012, 06:49:44 AM by lildragn »

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Adding footstep sound and particle effect
« Reply #1 on: October 21, 2012, 08:03:12 AM »
to be honest , most games cheat here for the sake of performance. They just use a footstep sound clip on loop, and make it fit perfectly with the walkcycle. Sometimes they resync them every 10 seconds or so too. Same with the footprints. Especially when running, you won't notice that the footprints appear slightly off of where the foot actually hit the floor.

I find it weird that your solutions didn't work though. For me the collision thing (yes, I'm a crazy perfectionist like you :D ) worked pretty well, since my runcycle has a definite frame where the foot touches the ground. So if there's an explicit frame like that in your animation, the collision should trigger. Did you double check everything?
Best,
Sven

tbelgrave

  • Playmaker Newbie
  • *
  • Posts: 42
    • Ispyr Inc
Re: Adding footstep sound and particle effect
« Reply #2 on: October 21, 2012, 08:18:25 AM »
For me the collision thing (yes, I'm a crazy perfectionist like you :D ) worked pretty well, since my runcycle has a definite frame where the foot touches the ground. So if there's an explicit frame like that in your animation, the collision should trigger. Did you double check everything?

Ha yes, my wife would attest to me being a perfectionist for sure :) But I like your idea here about adding the sound to a specific frame in the animation, how do you go about doing that? I was looking for a way earlier.

thx

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Adding footstep sound and particle effect
« Reply #3 on: October 21, 2012, 10:38:54 AM »
I personally did create a separate sound track for each running animation and played it each time the walkcycle looped. It takes exactly as long as the animation, and gets resynched each loop.

If you wanted it to be only the one footstep sound for all animations, then you'd probably have to do it manually. You could create a state with a next frame event, and a int add operator. Compare the int with your frame numbers (2 or 4 times, depending how long your walkcycle is) and see if this frame a sound needs to be made.
As far as I know the next frame event is free, so no performance issues there. You would however have to reset the FSM each time you start walking (global event) and stop it when you stop walking. You'd need to set the different footstep frames externally for each character and set the max frame number of your walkcycle for it to reset the current frame number each time it should loop.

Not difficult, not expensive, but not ideal either :D

I could write a get frame action, but that would be a bit more expensive per frame I think.

 
« Last Edit: October 21, 2012, 10:41:28 AM by kiriri »
Best,
Sven

kiriri

  • Hero Member
  • *****
  • Posts: 506
Re: Adding footstep sound and particle effect
« Reply #4 on: October 21, 2012, 10:51:00 AM »
wait, I got a better idea. Say each walkcycle animation features 2 steps. The steps will then probably be at around 0.25 and 0.75 in normalized animation time, if you animate like a pro ;) (doesn't matter if it's different, 0 and .5 is the same principle) So you can actually get the exact timing without any external input, which is probably preferable.

So what you can do, is get component with an object variable of the type "Animation" (see my thread in the tips and tricks section), then get from that the property "clip" . Get from that object both the length and frame rate.

Now with these two variables and the normalized time of the footsteps, it's simple math to get the exact time of the footsteps, either in frames or in actual time. If the clip is 40 frames long, and it plays at  60fps, it takes 4/6 seconds to loop. If the first step is at 25%, that is (4/6)/4 = 0,17 seconds .
Best,
Sven

tbelgrave

  • Playmaker Newbie
  • *
  • Posts: 42
    • Ispyr Inc
Re: Adding footstep sound and particle effect
« Reply #5 on: October 21, 2012, 11:00:13 AM »
Awesome thx kiriri! I'll give some of these suggestions a try and let you know result.

~t