Can you make the Cinemachine Virtual Camera Aim along a path?

I’m trying to parent a gameobject to a cinema virtual camera to move along a path while following another gameobject (the player). However, I can’t find an option to have the cinemachine camera aim at the path. The only thing I could find is changing the “Camera Up” to “Path” in the Body section, but that doesn’t actually change the rotation of the virtual camera. So the child of the Virtual camera, isn’t rotating.

Is there a way to make so the virtual camera is aiming at the direction of the path its moving along?

You can put both the vcam and the gameobject as children of a CinemachineDollyCart, which can follow the player while remaining on and rotating with the path.

I’m not sure I follow. When I make the Vcam a child of the Dolly, it as well as the child does not rotate along the path when following the player.

Can you show the inspectors of the path, DollyCart, and vcam please? Also please show the hierarchy.

8460755--1123325--upload_2022-9-23_15-40-52.png

I know camera up is set to default, but I did that because although on the camera window it seems to be rotating, its rotation actually isn’t changing

I made a child of the Vcam so that I could see where its pointing. In this image. You can see that it is following the “Follow Target” object (The Cube). But it is not pointing along the path.

Change the vcam’s “Body” setting to “Do Nothing”, so that it inherits its transform from the DollyCart parent. Then, you’ll need a script to make the cart follow the target.

Another option is to make a simple CM extension to make the vcam’s orientation come from the track. Let me know if you want to go that route, and I can help you out with it.

It depends which 1 is easiest. The programming for these I was doing in playmaker. If the extension is better, I don’t mind going that route.

Extension is easiest for sure. Here is one that pulls the rotation from the path. Add it to a vcam with TrackdDolly in the Body, and Do Nothing in the Aim. If you drop this script into your project, it will automatically appear in the vcam’s “Add Extension” dropdown.

using UnityEngine;
using Cinemachine;

/// <summary>
/// An custom extension for Cinemachine Virtual Camera that pulls rotation from the path
/// </summary>
[SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
public class RotationFromDollyTrack : CinemachineExtension
{
    protected override void PostPipelineStageCallback(
        CinemachineVirtualCameraBase vcam,
        CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    {
        if (stage == CinemachineCore.Stage.Body)
        {
            var dollyVcam = vcam as CinemachineVirtualCamera;
            if (dollyVcam != null)
            {
                var dolly = dollyVcam.GetCinemachineComponent<CinemachineTrackedDolly>();
                var path = dolly == null ? null : dolly.m_Path;
                if (path != null)
                {
                    state.RawOrientation = path.EvaluateOrientationAtUnit(dolly.m_PathPosition, dolly.m_PositionUnits);
                }
            }
        }
    }
}

8461247--1123409--upload_2022-9-23_13-50-24.png

1 Like

Right. Cool, I’ll try this out

1 Like

Let me know how it works out for you

1 Like

Hey man. This worked out perfectly! May have been more practical to use the dolly cart and make a follow script, but I like the control I have over the VCam. Thanks a lot @Gregoryl

1 Like