Today, I will be going over how to make a 3rd person camera behavior using State-Driven Cameras! I used an asset from the Unity Asset store called “Starter Assets — Third Person Character Controller” as the player. I also got the death and aim animations from the GameDevHQ program for this challenge.
Setting up the Animator
First, we have to make sure all the animations run when they are supposed to, or the State-Driven cameras won’t work.
I had to add the Aim and Death animations to this since it’s native to this asset. I will get into character animations and the animator in more detail when I get to that course and learn more.
To make this work, I set the Death animation transition to run when a trigger is activated and set the Aim animation to a bool. When aiming, set to true; if not, set to false.
Setting up the State-Driven Camera
After the animator is setup, we link the animation states to their respected cameras.
Looking at the picture above:
- When no other animation states are active, use the default camera.
- When the run state is running, switch to the sprint camera.
- When the aim state is true, set to the aim camera.
- And when the Death trigger happens, start the Death blended camera.
Scripting for Aim and Death
The asset already comes with the idle, walk, and run scripted for the player. We just have to add a small script for our aim and death.
Since I don’t have a health system, I just set the death to occur when I press the K key. Then I set the aim animation to be true when I press the right mouse click, and to false when I let off.
The scripting of this was just to make the recording easier but was simple to implement!
That was how to make a cool 3rd person camera behavior!
Next up, I get into camera transitions using the CinemachineBrain on the Main Camera!
Thanks for your time!