Interactive footstep system with blue prints in UE4
We want to create an interactive footstep system that plays the sounds according to the surface the player is walking on. A dynamic footstep system should also differentiate between the different movement types like crouching, walking and running.
- The first step is to set up the different surface types in the project settings. Go to: Edit -> Project Settings -> Physics, which you`ll find under the “Engine” category. There scroll down to the “Physical Surface” section and give each surface type a unique name like shown in the picture:
2. Now we need to create a material for each surface type like shown in the picture. These physical materials can be assigned to objects and surfaces in different ways. First, you can open the static mesh and within it’s details panel under “Collision” you can populate a “Simple Collision Physical Material”.
This setting can be overwritten in the details panel of the actor in the “Collision” section under “Phys Material Override”. And another place to look for physical material assignment is if you look in the details panel of an actor under “Materials”. Open the Material itself and in it’s details panel under “General” you can populate the “Phys Material” field. For landscapes, look in the details panel in the “Landscape” section. There you can assign a “Default Phys Material” or open the landscape material itself and check in its details panel, we can open its parent and in its parent the landscape layers in the “diffused textures” section. In the content browser, search for the respective landscpae layer files (filter: Misc -> Landscape Layer). Open the respective landscape layer and assign the physical material. To actually see the different landscape layers, go to Landscape Mode (Shift+3) and select the paint tool to see all landscape layers under “Target Layers”.
3. Make sure that “World Settings” is checked in the “Window” menu. Then click the “Word Settings” tab and open the “Game Mode” section. The Player character should be set up in the “default paw class”.
Open up the first- or third person character blue print. In the Viewport, select the Skeletal Mesh and open the blue print. Now navigate to the Animation tab. This is where we will attach the event notifiers that will trigger the footstep sound system.
If you are using blended animations, you should use EVENT NOTIFIERS and not sound play events, because this can cause weird overlapping and playback behaviors when animations are blended.
4. Now leave the animation tab and go to the blue print event graph. Here, we can set up the audio logic for the event notifier. We will use a AnimNotify Event to shoot a line trace. This will check on what surface type the player is actually on and set up a system to play the appropriate footstep sound.
The line trace will be shot from the player’s location. With a simple vector function, we will make sure is shots vertically into the ground. We then break the hit result to output the physical material value. From this we can get the appropriate surface type. We then use a select node and attach it to a Spawn Sound Attached node.
This way, the node will be automatically populated with the materials, and it will link a sound file to it respectively, and we make sure that the sound will be played at the root position of the moving player character.
5. Dynamic Volume modulation depending on character speed: We can use the speed variable from the event graph of the character mesh to vary the volume and sound of the footsteps. (Get Pawn Owner self -> Get movement component -> Get velocity -> Transform to Vector length -> Set Speed).
We will then reference the speed variable and normalize to a value we can work with audio (0-1) and feed it to a volume multiplier connected to the Spawn Sound Attached node.
Now, when we walk, we make more a kind of double part footstep sound, where you can hear heel and toe. And when you run, we get more of a single (louder) impact. This means we need different sounds for walking and running. That’s why we will duplicate the play logic for the walking to be able to attach running sounds.
After that, we want to use the speed variable to blend the walking and running sound, seemingly. To be able to get a nice blend, we are going to read the values through curves. Therefore, we have to create two xy-curves that will fade-in and out the walking and running sounds depending on the speed value.
7. Therefore, we have to create two curves (Misc -> Curve), name them: FC_Player_Foley_FS_Walk and FC_Player_Foley_FS_Run accordingly and set up the X and Y values like shown in the image.
At lower speed values it will fade in the walk sounds and at higher speed values it will gradually fade out the walk and fade in the run sounds, these values will then be normalized and head over to the volume value.
As a last step, we now have to assign the curves to the reference node.
8. After setting up the interactive footstep system, we then need to populate the Select nodes with the respecting sound cue. Let’s take a brief look at the sound cue setup, which features a generic attenuation curve and a little bit of volume and pitch modulation, but is pretty straight forward.