Skip to content

Scripts.FootStepKeyFrame

Wesley Haws edited this page Jan 1, 2017 · 10 revisions

##Scripts - FootStepKeyFrame

###What does this do?


This will play a sound at a specific key frame of an animation. This is used to produce footstep sounds based on the material that you're walking on. This will work with both terrain and basic objects at the same time.

###Who/What is this for?


Place this on the root of an object that needs to have it's keyframe access this script to play a sound.

###Setup


  1. Place this script on the root of your gameobject.
  2. Here are the following options
Inspector Param Type Description
Use Terrain bool Trigger on to only play sounds if on a terrain. Otherwise use both object and terrain.
No Sounds bool Do/Don't play sounds. Allows you to use an animation without breaking at each keyframe.
Material List Dict List Dictionary of material names and sound and volume options. (Number is depricated ignore it.)
Object Height Float Raycast to ground. If hit during keyframe, play the materials sound.
Position Adjustment Vector3 Start the "Object Height" Raycast from this position
Audio Source Audio Source What Audio Source the footstep sounds will be played from.
Use Override Volume bool Force the footstep sound be play at the "Override Volume" level for all sounds. If not enabled it will use the volume specified in the Material List
Override Volume float (0 to 1) Only works if "Use Override Volume" is enabled. Sound level to play footstep sounds.
Debug Surface bool For debugging. Will log what surface the "Object Height" raycast is hitting.
Debug Height bool For Debugging. Will log the height of the raycast.

Setup this how you would like. However it will error out if the raycast fails or the material was not found in the dictionary list. Below are some pictures of how I set it up:

Basic Setup

Basic Dictionary Setup

Once that is setup go into your animation that you want to play footstep sounds and add the keyframes.

  1. In Unity Click the Window Tab > Animation
  2. With the "Animation" tab open select your NPC Object that has your animations attached.
  3. In the "Animation" Tab select your target animation
  4. Go to the exact point in the animation and add a keyframe Add Animation Event
  5. In the dialog box that appears select "PlayFootStepSoundKeyFrame()"
  • If this isn't an option that means that you have added the "FootStepKeyFrame" script incorrectly. Adding Event Keyframe
  1. Add as many keyframes that are needed.
Clone this wiki locally