Footsteps don’t just play themselves – you have to define how and when to play them.

While all the hard work of finding the correct footstep effect, playing the audio clip and managing the prefab is taken care of without much for you to do, you still need to define how and when footsteps will be played.

Auto Play

The easiest way is to automatically play footsteps in regular intervals when a game object with a Footstepper component is moving.

This is set up on the Footstepper component – follow the link above for details.

Animation Events

This is the best way to perfectly time footsteps with your animations – either set them up in a Mecanim animation or the Animation window.

In Mecanim animations, it’ll look like this:

In the animation window, it’ll look like this:

In both, you’ll have to define or select the Function that will be used. You can use the following functions to play different footsteps:

  • Footstep, FootstepIndex
    Plays walk, run or sprint footstep based on the game object’s movement speed.
  • FootstepWalk, FootstepWalkIndex
    Plays the walk footstep.
  • FootstepRun, FootstepRunIndex
    Plays the run footstep.
  • FootstepSprint, FootstepSprintIndex
    Plays the sprint footstep.
  • Jump
    Plays the jump footstep.
  • Land
    Plays the land footstep.
  • FootstepCustom, FootstepCustomIndex
    Plays a custom effect.
    This requires an Int value (foot index) and a String value (custom effect name).

You might have noticed that footstep, walk, run and sprint functions also have an Index version. They’ll let you directly play a footstep for the defined index without checking the animation weighting.

Which foot will be used is determined by the Int value you pass on in the animation event – this is the Index that will be used. The first foot will be index 0, the second foot will be index 1, etc.
If you don’t want to use a specific foot (e.g. for jump or land), use -1 as Int value. This will use the game object itself instead.

Custom effects (FootstepCustom and FootstepCustomIndex) require an additional String value to pass on the name of the custom effect that should be played.

Footstep Trigger

Footstep Trigger is a component that plays a footstep if a Footstep Source enters the game object’s trigger (i.e. a collider with Is Trigger enabled).

Select the Footstepper that will be used to play the footstep.

The Foot Index defines the index of the foot the trigger is used for. This is used by index prefabs of footstep effects to spawn different prefabs based on the foot index.

The Time Between can be used to prevent too many footsteps playing from the trigger.

Enabling Raycast Position will use the footstepper’s raycast to find the ground position (and normal) below the game object.

Enabling Limit Layers will only allow game objects from the defined layers to cause a footstep.

Please keep in mind that Unity requires a Rigidbody component to be involved for a collider/trigger to recognize something entering it.

Scripting

If none of the available ways to play a footstep suits your needs, you can always use custom scripts – e.g. as part of your player controls.

Calling Footsteps

Simply get the Footstepper component that should be used (e.g. adding it as a public field in your script) and you’re able to call the same functions used by animation events (for the footsteps, you’ll want to use the Index versions):

  • FootstepIndex
    Plays walk, run or sprint footstep based on the game object’s movement speed.
  • FootstepWalkIndex
    Plays the walk footstep.
  • FootstepRunIndex
    Plays the run footstep.
  • FootstepSprintIndex
    Plays the sprint footstep.
  • Jump
    Plays the jump footstep.
  • Land
    Plays the land footstep.
  • FootstepCustomIndex
    Plays a custom effect.

The functions require an int parameter to pass on the index of the foot that should be used (or -1 to not use a foot und just use the component’s game object).

The FootstepCustomIndex function also requires a string parameter to pass on the custom effect’s name.

Set Grounded

Additionally, you can set the Footstepper‘s grounded state – this is only changed via scripting and allows you to prevent walk, run and sprint footsteps from playing.

Call the SetGrounded function, which requires a bool parameter. E.g. footstepper.SetGrounded(false) sets the footstepper to not be grounded.

In the demo, this is used by the 2D example while jumping.

Namespace

When using Footstepper‘s classes or components in your code, make sure to include the GamingIsLove.Footsteps namespace at the top of your script file: