If you want to make a 2D game, Cinemachine virtual cameras have you fully covered. Let’s take a look at setting up a 2D camera for your game!
To get started, create a Cinemachine>2D Camera.
By default, the 2D camera uses the Framing Transposer Body setting, which is perfect for 2D gaming cameras. Right away you should see a message telling you that the Framing Transposer needs a Follow target.
Assign the a target object to the Follow. I use the Player for this example.
For a true 2D gaming experience, we need to change the Projection of the Main Camera.
Under Projection, change the drop-down to Orthographic.
For an easy floor demo, I create a cube object and stretch it out to represent the 2D floor plane.
The cube should look like a flat floor plane in the Game View. Now Bob here can run around in the Game View as seen in the cover image gif.
Confiners
Confiners can be used to keep the camera from moving past designated areas. Here I create a 3D wall to stand between the camera and the Player.
Select the 2D camera in the Hierarchy and add an extension of type Cinemachine Confiner. The cube wall is assigned to the Bounding Volume, to act as the space where the camera will be confined.
Once the Confiner is assigned to the Bounding Volume, the camera will be able to see through it.
Now the camera will follows the player left and right, but it stops following the player once it reaches the boundaries of the confiner object.
That’s it for 2D cameras. Thanks for reading!