Day 103: 2D Cameras Using Virtual Cameras

Simon Pham
3 min readOct 13, 2023

--

In this article, I’ll guide you through the process of setting up 2D cameras using Virtual Cameras.

Scene Setup

I’m going to set up a straightforward scene with a capsule character and a plane.

Next, for the 2D camera setup, go to the Main Camera and select “Orthographic” from the Projection dropdown list.

Now, add a cube to our scene and increase its size to serve as the floor for the 2D environment.

Next, include a 2D Camera in our scene by going to GameObject > Cinemachine > 2D Camera. Ensure the camera is focusing on the character with the Body set to Framing Transposer and Aim set to “Hard Look At.” Also, add a little Lookahead Time and Lookahead Smoothing to make the camera follow the character more smoothly.

If you look at the gif above, you might have noticed that the edge of the floor is visible in the camera view. To hide it from the camera, we need to confine our camera.

To do that, start by creating a wall to act as the camera confiner.

Next, add the CinemachineConfiner extension to the camera, select “Confine 3D” from the Confine Mode dropdown list, and assign the Confiner GameObject (the wall we created) to the Bounding Volume field.

Now, hit “Play” and see the result:

You’ll notice that the camera effectively follows the character until the character moves beyond the wall, which acts as the constraint area for the camera, causing the camera to stop following.

--

--

No responses yet