Geek Culture
Published in

Geek Culture

Easy Camera-Follow without Coding

Objective: easily follow the player using a virtual camera

A few weeks ago, I published a tutorial about a camera-follow logic that should resemble the one from the Super Mario series: not just a simple lock on target but a more complex behaviour in which the camera follows the character only if it overcomes some thresholds.

If you’re interested in this “low-level” coding, you’ll find it here.

As it happens often while studying a subject, time lets things settle and rearrange better in your mind: the same result can be achieved using the Cinemachine package.

Let’s revise all the steps. First, install the package.

Once it is done, we can create cinemachine objects. Let’s create a virtual camera (VC).

The creation of the first virtual camera will give a Cinemachine Brain component to our main camera: in this way it will follow the complex behaviours we can set up with the VCs.

The only thing we need in the VC right now is the Follow property and we’re going to populate it with the player transform, or any other object we want to follow.

We now have many possibilities in terms of following, but to create the same behaviour as the one in the previous tutorial we have to choose “Framing Transposer” in the body section.

This will open up a funny section, full of options. Some of them we already found and talked about in other tutorials: zones.

Before continuing, let’s have a look at the game view. Those coloured areas are the zones.

Dead Zone

The dead zone is the uncoloured one in the middle of the screen, right where the yellow square (the target) is. This is the zone in which if you move your target object the camera will not follow it. I chose quite a narrow zone (it’s just my taste), very small in height. I also applied a little x-offset to not have the character right in the centre.

While the yellow square stays in the dead zone, no following is performed.

Soft Zone

The soft zone is the blue one. When the tracked object reaches it, the VC starts a smooth following, meaning that there will be a sort of delay and the camera is not locked on target: when you stop moving, the VC will take its time to bring the yellow square again in the dead zone.

You can even extend the soft zone to the entire screen by checking “Unlimited Soft Zone”.

Hard Zone(?)

This is the red one, I call it hard as opposed to the soft one, but there’s no name for it in the inspector: once you set dead and soft zones, the hard one is automatically obtained. When the tracked object reaches this zone, the VC will follow it much quicker: in fact, there is no possibility to go beyond the limit between blue and red.

One last mention goes to the Damping section. You can set values along each axis: the lower the value the more aggressive will be the camera-follow, with more responsiveness and quicker camera movements.

To make the zones disappear from the game view, you just need to deselect the virtual camera in hierarchy view and enjoy the result!

If you liked it, clap to it! Check out my games or buy me a coffee: every kind of support is appreciated!!

--

--

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
Daniele Quero, PhD

Daniele Quero, PhD

719 Followers

A professional developer with passion for game developing and skill-growing. A former Nuclear Physics Researcher who changed his life to pursue his dreams