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 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.
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);
}
}
}
}
}
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