2D Cameras in Unity Using Cinemachines Virtual Camera
Objective: To understand Cinemachines 2D camera and help get your next project setup.
How to Add a 2D Virtual Camera to Your Scene
This is a nice easy process! Make sure you have the Cinemachine package installed from Unity’s Package Manager, look along the top tabs for ‘Cinemachine’ → ‘Create 2D Camera’.
How to Get the Right Setup for Your Project
When you add the 2D camera into your scene, you will notice that it looks like other virtual cameras and really nothing has changed. This is because we need to take a few more steps to get this functioning (as I am in a 3D project):
- Assign a ‘Follow’ target to the field. E.g. Mine was the capsule
Leave the ‘LookAt’ field blank.
- Set the ‘Field of View’ under the ‘Lens’ setting to 1.
- Navigate (or move/adjust) the camera around the scene until you like to position it is in. Then make sure to set this position by going up to the top tabs and selecting ‘Game Object’ → ‘Align with View’ or alternatively pressing Ctrl + Shift + F.
- Now just adjust the ‘Camera Distance’ to whatever you like! I personally set mine to 500.
- Finally, you could change your Main Cameras ‘Projection’ mode to ‘Orthographic’.
This is the final changes:
Success! The 2D camera works!