Footprints are GO!
Hi and a warm welcome to this week's blog post!
This week we're going to be looking at Tove's new fancy pants footprints. Previously she cast a shadow which grounds her in the scene nicely, but as she's going to be spending a great deal of time in the snowy wilderness, we thought it's be super neat if she left a trail of foot prints in the snow - and maybe throw in some footfall particle effects whilst we were in the neighbourhood!
In fact, once we got something up and running we decided to use the effect to varying degrees in all our scenes. We put in variables so that the footprints colour and intensity can be set on a scene by scene basis so we could even use them in a subtle fashion in the interior scenes.
Anyway, that's the overview. We're gonna take a step-by-step look at how we created them. We're not going to be going into super tetchy details so hopefully it'll still be an interesting read for the non gamedev folks!
Unity's projects are the base building block that we built up from. They're essentially project an image onto a surface, in our case the flat shape of a boot-print! This is neat as they can work on different terrain, it doesn't matter if you have slopes or steps in your environment they still work as the footprint is projected down from above. You can read more about them here if you like.
Custom Footprint Shader
So you can use the basic multiply projector shader than is in Unity's standard assets and it will project your image onto your scene. It works well but we needed to add some more functionality to make it work how we wanted, so we created a custom footprint shader using the standard one as a basis.
First thing was we wanted to add was the ability for the footprint to fade out over time so there is no noticeable 'POP!' when we kill it.
The second thing we wanted was a tint colour. We'd worked out early on that the effect would add a nice touch to most of our scenes but would need to be adjusted to suit. It might be quite dark and blue tinged in the snowy exteriors but more subtle and warm when used in dusty interior spaces.
That was all the functionality we needed, pretty simple really.
How do we Trigger a Footprint?
The next question was how are we gonna tell the game when to place one of these things on the ground? We'd need to know when the foot had planted and we might not want it for all animations (for example we wouldn't want it for when Tove climbs a ladder).
The answer was actually pretty straight forward, we used animation events. These are triggers you can add to an individual animation's timeline, when the animation is playing and hits the trigger/anim event you can make it do STUFF!
In our case that 'STUFF' would be to trigger a 'footprint function' that would place our footprint for us.
The nice things about using animation event's for this is that it's not automated, you can use your judgement to say which anims you want to have footprints, they will only trigger on animation you add the events to so there's a great deal of control.
As well as triggering functions this way you can also pass them bits of extra info in the anim event which is nice. In this case we decided to pass either the string "Left" or "Right" along with the function call.
So we have this function that slaps a footprint down, but what does it actually do? Handily I remembered to capture some video footage as I was implementing the footfall VFX, so let's have a look at what it does step by step...
-At the point the anim event is triggered it gets the position of Tove's foot and uses its TX and TZ to position the footprint projector in the first place beneath her planted foot.
-It also gets her foots rotation and used that to rotate the projector so the footprint will match the rotation of her foot (you can see this below).
-Remember that string ("Left" or "Right") we passed to the function from the anim event? If you look at the above video you can see that all the footprints are shaped for the left foot! So to fix that we now we use the passed string ("Left" or "Right") to pick which image we want to project down onto the ground, the left or the right foot (we probably could have got away with having a generic footprint that was used for both feet but what the hell I was feeling fruity so I added it in). You can see this update below:
-In the above examples you can see that once it reaches a limit of 6 footprints it kills the oldest one and creates a new one in the fresh footfall position. In order to make that look nice we use fades, so by the time we need to kill a footprint it was already conveniently faded from sight! We records the game time that the foot landed on (from when the anim event was triggered) and then works out how much time has past so it can calculate how faded out the footprint should be.
-Finally, once the footprint has faded out completely we kill it and it goes to footprint heaven.
The last ingredient was the footfall particles to simulate snow or dust that is getting flung up with the impact and wake of each footstep. As we now had all this info about where the footfall was and what rotation it was it was a simple case of moving a particle emitter to the foot once it had landed and have it play it's particle 'POOF'
The only extra condition we added was that we didn't want this particle 'POOF' to trigger for any old footfall, just when Tove is running (it was a bit overkill for when she is just walking about). In order to do this when the foot lands we check one of her animation parameters in her animation network which tells us preciesly that.
Simple, if the check says she's not running, don't trigger the particle 'POOF', if she is then fill your boots!
Projector Ignore Layers
Another neat thing about projectors in Unity (versus the real world) is that you can set them to ignore certain parts of your scene. As you can imagine we don't want the footprint to be projected on Tove, so we set it to ignore our Character Layer. In fact we wanted to ensure that only the elements we absolutely required to receive footprints were the once that were considered. So we created a new layer 'Receive_Footprints' and added any floor meshes and terrain we wanted to get the footprint treatment in there pronto.
As well as making it more efficient it also cuts down on the amount of visual artifacts you'll get. The projector isn't particularly smart and just projects an image down so you can sometime get footprints appearing where you don't want them, smeared down the vertical part of a step or even appearing on the roof mysteriously above where Tove is running (kinda creepy)! So yeah, using those ignore layers is a double win.
ANNNND...That's your lot, you can look again at the top image to see it all working together in a scene! We hope you found that interesting, it's quite cool how you can layer up lots of simple steps and get something that's pretty effective!
Until next time,
Alex & Tom