Virtual Cameras w/ Cinemachine in Unity 2020 — Part 7

GameDev Dustin
6 min readFeb 27, 2022

Virtual Camera Body (Tracked Dolly)

“This Virtual Camera Body algorithm restricts the Virtual Camera to move along a predefined path.

Use the Path Position property to specify where to put the Virtual Camera on the path.

Use Auto-Dolly mode to move the Virtual Camera to a position on the path that is closest to the Follow target.

When enabled, Auto-Dolly automatically animates the position of the Virtual Camera to the position on the path that’s closest to the target.

Tip: Choose your path shapes with care when using Auto-Dolly mode.

This becomes problematic on paths that form an arc around some point. As an extreme example, consider a perfectly circular path with the Follow target at the center.

The closest point on the path becomes unstable because all points on the circular path are equally close to the target.

In this situation, moving the Follow target small distances can cause the camera to move large distances on the track.

Ever seen a roller coaster?

Tracked Dollies are sort of like that, only a lot less bendy and fewer extreme turns.

We also want to avoid any geometry in our tracks that would make it so the target game object is equidistant to more than one point on that track.

For example if your track is a perfect circle around the target game object, technically every point on the track is equidistant to it.

The Tracked Dolly mode operates by picking the nearest place on the track to position the camera, so you can get some weird behavior if there is more than one point the same distance from the target game object.

Make a Path

For this mode to work, we need to first create a path that our camera will slide along.

Just create an empty game object, zero out the position, and add the CinemachinePath component.

You should see something similar to the above in your scene view.

Our default Cinemachine Path settings, as shown above, include just two waypoints.

We can add more here using the plus sign, but first let’s look at how we can modify our path using these waypoints.

So, each waypoint has two gizmo arrows for each axis.

One will moved the path in that direction, and the other will do a Bezier curve so that you can create curves in your path.

So, I’ve added 2 waypoints using the plus sign.
Using the gizmo arrows I shape it and lengthen it as needed.

Now, if I like, the settings for each Waypoint has a setting called “Roll” on each point.

This lets me put an angle on my track, whereas up until now I’ve only moved it vertically and horizontally without any rotations applied.

With just the X axis Roll setting on Waypoint 2, I’m able to angle my track as shown above.

I kept adding waypoints and shaping until I have a track around my two main target game objects that will be moving around in the scene.

Now I need to assign my Dolly Track Path game object to the Follow field and the Path field on my VCam.

NOTE: Actually, just the path field, do not assign to the follow field for now!

At this point, the VCam attaches to the path but it doesn’t really move on the path.

Now, there is a Position Offset setting that we can use at runtime to move the Camera along our track.

Positive values will move it forward and negative values backwards.

Pretty cool.

Now this worked when I had the DollyTrackPath game object assigned to the VCam Follow field.

Once I took the DollyTrackPath off the follow field, it no longer worked.

To get the same behavior as the Position offset when the path was assigned to Follow, we now use the Path Position field with nothing in our Follow field.

As we can see above, this works very similarly.

We can redefine how we segment our path with the Position Units field.

Auto Dolly

So, now, we can add our path game object to the follow field and enable the Auto Dolly and we’ll get the expected result.

Now I want to set Auto Dolly to enabled so that the VCam will move along the track without my input.

Note that I have Search Radius set to 0, because there are 5 waypoints on my path.
I want it to search the entire path when calculating its position on the track.

The Search Resolution will let you dial in just how precise you want to be on the track.

Position Offset works as shown before, but now that the auto dolly is working it only acts temporarily from the current position of the VCam on the track before the auto dolly then takes over again.

This is probably useful for dolly tracks that are likely to have the VCam in one spot for long periods of time before going onto the next waypoint in your game.

That’s it for this article!

--

--