Search code examples
c#unity-game-enginecinemachine

Trying to move Tracked Dolly through path positions on key press


I am try to set it up so that when I press E or W, my camera will move through the waypoints I set on a dolly track.

When increasing the path position manually it works, but when I try writing a script to do it and adjust that value, for some reason it wont let me add the tracked dolly to the component's field (it always says None).

using System.Collections;
using System.Collections.Generic;
using UnityEngine;
using Cinemachine;
using UnityEngine.InputSystem;
using UnityEngine.InputSystem.Controls;

public class Move : MonoBehaviour
{
    public CinemachineTrackedDolly dolly;

    public void OnRotateRight(InputAction.CallbackContext context)
    {
        dolly.m_PathPosition = dolly.m_PathPosition + 1;
    }

    public void OnRotateLeft(InputAction.CallbackContext context)
    {
        dolly.m_PathPosition = dolly.m_PathPosition - 1;
    }
}

my screen

I have tried many different cinemachine blocks and just cant figure out what im doing wrong. I am also using input system for easier use of different key presses.


Solution

  • So I found out the issue. You cannot manually apply which Dolly to track for whatever reason. You have to do it through script and tell it that the tracked dolly is your camera.

    public  CinemachineTrackedDolly dolly;
    
    public CinemachineVirtualCamera currentCamera;
    
    void Update()
    {
      dolly = currentCamera.GetCinemachineComponent<CinemachineTrackedDolly> ();
    }