The work to add footsteps is mostly a “Unity thing” and not a “Motion Controller thing”. That said, I’ll take you though the steps here and point out the animations that I use.
The meat of handling foot steps is adding animation events to the walk and run animations. These animation events will be picked up by your custom component and then you can do whatever you want from there. For example, you could play a sound, place a footprint on the ground, or trigger some other action.
Important: Because you’re modifying the animations, you’ll need to also modify the animator to use your new animations. To prevent Unity from replacing your changes during an update, you’ll want to make changes to a copy of the animator and a copy of the animations. Then, you’ll use these.
We’re just using standard Unity animation events to get notified when the animation has the foot hit the ground. That means we’re actually going to have two events; one for the left foot and one for the right foot.
We’ll start by finding the walk animations. The easiest way to do this is to just go to the copy of the animator you created, double-click on the walking sub-state-machine you’re using, and click the motion field in the walk state.
Now you know the exact animation that’s being used.
Since you’re going to be modifying the animation clip in the FBX, you’ll want to create a copy of the FBX.
Ensure your copy of the animator is now using this new animation and clip in the sub-state-machine state instead of the original one. This is just a standard drag-and-drop into Unity’s motion field.
At this point, your new animator is using your new animation clip. Now we need to add the animation events.
If we go back to our copy of the FBX, we can select the clip we want to add animation events to.
Here we’ll position the animation timer where we want it and add an animation event for the right foot and the left. We’ll use an int of “0” to tell us the right foot is down and an int of “1” to tell us the left foot is down.
With that, our animation events are setup. Now we just need something to capture them.
For this, we need a custom MonoBehaviour. This is just a standard Unity component that has a function whose name matches that of our animation event functions above: OnFootDown.
Inside the function, we can do anything we want. In this example we’ll just write a debug statement that says our foot is down.
public class FootstepHandler : MonoBehaviour
public void OnFootDown(AnimationEvent rEvent)
Debug.Log("Foot down: " + (rEvent.intParameter == 1 ? "left" : "right"));
Now we add the new component to our character and we get notified of footsteps.
Obviously you can get a lot more advanced and play sounds, leave footprints, etc. This just shows you the basics.
Because the Motion Controller allows you to use different movement styles, you’ll need to determine which “walk/run” motions you care about. Those will determine which animations you’ll need to copy and add animation events too.
Follow the steps above for the motions and sub-state-machines you care about and you’ll be able to find the walk and run animations to modify.
Walk Run Pivot and Basic Walk Run Pivot use:
Walk Run Strafe, Walk Run Rotate, and Basic Walk Run Strafe use:
As you use my motion packs, create your own motions, or use your own animations you’ll need to be aware of the additional walk animations that may come into play. Again, going to the animator sub-state-machines you’re using and clicking on the walk/run state animation is the easiest way to find the animations you’ll need to add animation events to.