Cinemachine camera to follow your player
Objective: Follow the player with a cinemachine camera
Cinemachine is a great asset that now comes with Unity and is free. You can find it in the package manager window from your project. Window -> package manager. Once there, you need to click on the Unity registry option and it will show the list of assets that come with Unity.
To get the camera to follow the player it is very simple and requires no code what so ever.
Once Cinemachine is installed, click Cinemachine at the top of the editor and select virtual camera.
This will attach a component to the main camera and it will now follow the newly created virtual camera.
Click on the virtual camera and you will see some options that need to be filled in. You can see a follow and look at option that we can drag an object into for the camera.
In my instance I dragged in the hips object of my player model as this gave me the best angle. You can experiment with dragging different body parts of the player.
I also changed the binding mode from ‘lock to target with world up’ to ‘World space’, this gave me the freedom to adjust the rotation of the camera so that it will always look at the player from that angle.
I made one last adjustment to my virtual camera and that was changing the X,Y and Z damping to 0. This is the amount of sway that the camera with give when the player is moving.
And that is it for setting up a Cinemachine camera that will follow the player.