playMaker

Author Topic: How to add footstep sounds when working with Mecanim[SOLVED]  (Read 8848 times)

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
How to add footstep sounds when working with Mecanim[SOLVED]
« on: October 10, 2014, 03:34:05 PM »
unity manual quote:

Can you add animation events to Mecanim?

This is high in our priorities for future development. For the time being, we suggest using additional animation curves to simulate events approximately. Although this technique doesn’t recreate events exactly, many of our users have reported it as useful.

Play maker details

Currently using

Movement : This FSM controls the player movement and targeting using the axis vector and feeding it to the
character controller move vector.

Mecanim : This FSM feeds the Player mecanim animator with speed data and trigger data. It watches the
character controller velocity and feeds to the mecanim animator. The mecanim animator uses this data to
switch from idle to running states.

speed is the variable used, with this open in the inspector and playing the value goes from 0 - 5

The animation in use is running Details:

0.0 - 12.0 @ 30fps

Question: How would you setup an FSM to play a single footstep sound for when each foot should be touching the ground based on the input from the user?

I am using FPS PlayMaker Kit with some minor changes.



« Last Edit: October 12, 2014, 02:32:47 PM by colpolstudios »

mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: How to add footstep sounds when working with Mecanim
« Reply #1 on: October 11, 2014, 01:18:59 AM »
What I do is add animation events to the animation clip mecanim is using-

So for footsteps I'll use "SendEvent" to send an event called "footstep" it will send those events to fsm's on the object with the animation clips-

Then I have a simple fsm with an empty start state- and a transition called "footstep" the state that goes to uses "Play random sound" and I drop a couple different footstep sounds in there-

So to recap I add animation events on the keyframes where the feet touch the ground- and send events on those frames to play random footstep sounds-
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: How to add footstep sounds when working with Mecanim
« Reply #2 on: October 11, 2014, 12:51:36 PM »
Within the window to add an animation event I have these options.

Function, Float, Int, String and Object.

By default the function is named "NewEvent".

I am not sure what to put into the fields:(

I am now getting this error msg: AnimationEvent 'Footstep' has no receiver! Are you missing a component?

« Last Edit: October 11, 2014, 02:38:41 PM by colpolstudios »

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: How to add footstep sounds when working with Mecanim
« Reply #3 on: October 11, 2014, 06:35:54 PM »
I seem to have this solved, but still in testing.

I will keep you posted and many thanks for your help.


mdotstrange

  • Hero Member
  • *****
  • Posts: 555
    • Can't code? Who cares! Make games anyway!
Re: How to add footstep sounds when working with Mecanim
« Reply #4 on: October 11, 2014, 06:40:59 PM »
Good to hear! for anyone else having trouble with this- here's some more details

So to use SendEvent- in the field "NewEvent" replace that with SendEvent and in the string data field type the name of the event you want to send like footstep- see the attached images

So you are telling it to send an event with "SendEvent" and the event you are sending is a string in "footstep"

Then in any fsm attached to the object the animation controller is on- they will receive the footstep event whenever it is fired- I attached two different simple ways your fsm can receive the event to play a footstep sound
Indie game dev and instructor at the Strange School. Learn Playmaker at the Strange School!

colpolstudios

  • Sr. Member
  • ****
  • Posts: 370
Re: How to add footstep sounds when working with Mecanim
« Reply #5 on: October 12, 2014, 02:32:11 PM »
Thank you so much the pictures helped me lots