Camera! Follow Me!- Game Dev Series 92

S.J. Jason Liu
2 min readJul 27, 2021

--

Objective: create a following camera by using Cinemachine.

We have used Cinemachine virtual camera to make some cutscene. This time we will use it to replace the game camera to follow Player.

In this article, we will set a Cinemachine camera as main camera and adjust the rotating issue of Player.

Start with virtual camera

Create a virtual camera into scene. If you have no Cinemachine drop down menu from the top, you may install it from Package Manager.

Adjust the camera in Inspector. Drag in Player gameobject to “Follow” and “Look At” to make sure Player is the only target.

We can also adjust some value under tab “Aim” to present a better angle.

Rotating issue

However, if you play the game in this way, you might see this.

The camera also rotate when Player has rotated. Because we make camera follow Player but we rotate the whole gameobject of Player when turning around.

To fix this, we can simply adjust the rotation only on model gameobject. That way the facing of Player gameobject would never change.

Create a gameobject variable in Player script, and use it to replace the origin rotate gameobject.

And now camera would perfectly follow the Player.

--

--

S.J. Jason Liu
S.J. Jason Liu

Written by S.J. Jason Liu

A passionate gamer whose goal is to work in video game development.

No responses yet