How to Setup a Panning Camera in Unity Using Cinemachine and Timeline

Objective: To create a panning camera for our sleeping guard cutscene.

Virtual camera one panning up and then blending into the second virtual camera

We have setup the 2 virtual cameras that now blend between our character Darren as he reaches into the security guards lap to steal the much needed keycard. Let’s take this a step further and incorporate a panning camera for our first virtual camera. We are going to move it slightly to the right and up, also adjusting the angle along the way.

Using the Timeline editor to create Keyframe Animations for small changes to game objects positions, scales or rotations is a fantastic option, as it is very simple to use! Let’s get started….

Create Animation Track in Timeline

The first step is create an Animation Track in Timeline by right clicking on the left hand side → Animation Track. We are then going to drag our ‘Over_The_Shouder_Darrenvirtual camera into the newly created field and it is going to ask us if we want to create an Animator component on our ‘Over_The_Shoulder_Darrenvirtual camera game object? Yes we do:

Animation track → Dragging game object into field → Adding Animator component to game object

Creating the Keyframes for the Animation to Move Between

Let’s first get a little more understanding of what we are looking to achieve here using Keyframe Animations. As I am simply looking to move (pan) a virtual camera a small distance to add some depth to our cutscene, what we need to do is create 2 separate keyframes that our virtual camera is going to move between. The first keyframe is going to be it’s starting position and the second is it’s final destination, as Unity interpolates between each keyframe.

Let’s take a look at setting up our first keyframe, by pressing the ‘recordbutton on the Animation Track:

Record button ‘On’

You will now notice that your Animation Track is now red with the textRecording’. Any changes that are now made to this game object will be captured and a keyframe will be created on the Timeline Playhead line (white line). Note: If no changes are made, then no keyframe is registered. Let’s dive into this a bit further.

As discussed above, we can’t actually create the starting points keyframe unless we move the game object. So to get this setup, I am simply going to move the virtual camera in any direction and then place it back to where it was (hitting the record button again to end the recording) and then notice the little keyframe symbol pop up on your Timeline where the Timeline Playhead is:

Recording the first keyframe

Creating the Second Keyframe

Let’s now move the Timeline Playhead forward on the Timeline (to say 1:50) and create our second keyframe. Hit that ‘Recordbutton again, and this time let’s move the camera to the end position and once we are happy with it, press ‘Record’ again.

Recording the second keyframe

We now have our second keyframe on the Timeline and we can actually drag the Timeline Playhead and watch the camera pan between 0 and 1:50.

Camera panning from keyframe 1 to keyframe 2

Unity will now interpolate between these 2 positions.

How to Delete a Keyframe

If you have accidentally created the wrong animation or you just simply stuffed up (like I tend to do) and you want to delete the keyframe and start again, you can’t do it directly in Timeline, you will need to right click on the animation trackEdit in Animation window (this will now open the Animation window for you if it wasn’t already open). From here locate the keyframes you want to delete, right click on them → Delete:

Deleting a keyframe

--

--

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