Working with Cinemachine

Using 2D Virtual Camera & 2D/3D confiners

Among all of the 3D virtual cameras Cinemachine offers they also offers a virtual camera for 2D games which also has the same functionality as the 3D counterparts and also has everything such as Noise and extensions included.

As you can guess the 2D version of the virtual camera works great for 2D games such as side scrolling and top down games.

Setting Up the 2D camera:

Just like with all the other cameras, the 2D Camera can be found under the Cinemachine tab.

When the 2D camera is first added you will noticed that the perspective is still within a 3D environment. To fix this we will need to adjust the Projection in the Main camera from Perspective setting to Orthographic.

You can see the difference between the two settings below, the Orthographic projection makes the Plain object invisible because it is too thin.

Overall the virtual camera setting is very similar to the other game cameras mention previously, but the 2D camera also has the ability to add confiners. Although it isn’t limited to just the 2D camera it works best when it is applied to it.

Setting Up confiners:

Confiners are usually used to limit the camera movement to prevent the camera from showing areas that isn’t suppose to. It also works as a stage bracket to help player know where the start and end of the stage is in a 2D game.

To add an confiner we first need to create or add an object to the scene that will be the size of the boundary. This can be 2D or 3D, as long as it is bigger than what the camera can see.

I made a 3D cube as my confiner.

In the 2D camera we are going to add the confiner extension. It will allow you to pick between an 2D object and an 3D object, since my cube is 3D I will pick the 3D Mode, and drag my object into the slot.

Automatically you will see that the cube although still visible in the Scene view, has indeed become invisible in the game view. The confiner cube also now has an yellow outline indicating that it has become a boundary for the camera.

Now when you play the game, you will noticed that once your player starts moving towards the edge of the boundary the camera stops moving outward once the boundary has been collided with.

the player is indicated by the red CM icon. The white lines indicated the view and position of the virtual camera.

--

--

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store
Simon Truong

Simon Truong

A Designer, an Illustrator and a massive tech geek aspiring to become a professional Unity Developer.