Dynamic Footstep FX
The visual assets aren’t necessary for this but if you like the look, support TomkaGS by purchasing their Autumn Forest asset pack here.
First, we need to set up an event to play the sound of the footstep. To do this, we’ll make new Notifies during each step in the animation. Inside the Animation Sequence scrub along the timeline and find the moment the character’s foot connects with the ground.
Right-click in the Notifies channel and select Add Notify.. -> New Notify. Name it Step. You can do this across multiple animations as well. So each Step notify will fire off the event in the Animation Blueprint.
Open the Animation Blueprint, right-click in the graph and search for Step.
Each time this event is fired off we want to call SphereTraceByChannel and trace down on the Z-axis to a distance that will reach the ground. In this case, we use a SphereTraceByChannel so that we can give it a radius of 10.
We do this to more accurately represent the character’s foot. As an example, in this picture of a bridge if we used LineTraceByChannel there might be a chance the trace goes between the boards. The sphere radius will be less likely to, well, fall between the cracks.
Next we’ll need to create the physic surfaces in Project Settings -> Physics -> Physical Surface. Add a Surface Type for each one in your game.
Then right-click in your Content Browser, go to Physics and create a Physics Material. Once you create one you can duplicate it using CTRL + W for however many surfaces you need.
In each Physics Material asset, select it’s corresponding Surface Type.
Depending on your Material setup, you can either apply these Physics Materials to the parent Material or each Material Instance.
Now in the Animation Blueprint we can Get Surface Type. This returns an Enumerator we can Switch from. With a Break Hit Result from our trace we can get the location of the hit to use Play Sound at Location. I promote the hit location to a variable to use later. Maybe we want to play a particle system at that location.
Select the sound for each surface type.
Setting Draw Debug Type to persistent we can see the various surface hits.
Using surface data we can make many things dynamic. Think of when a bullet hits a surface and has different VFX for each surface.