Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Resolved How do I set the speed of the Cinemachine Dolly Cart programatically?

Discussion in 'Cinemachine' started by monahajt, Sep 29, 2022.

  1. monahajt

    monahajt

    Joined:
    Nov 28, 2017
    Posts:
    15
    Hello,
    I am setting up a GameObject to follow a dolly path, and I've got all that working. Now, I would like to be able to change the speed of the dolly cart based on user input. So if `isBreaking` is true, it would slow down (and zoom in), if `isBoosting` is true, it speeds up (and zooms out), otherwise it would use the default speed. This game object has this script and the `CinemachineDollyCart` script on it. Any chance I can control the speed from this script?

    Code (CSharp):
    1. void FixedUpdate()
    2.     {
    3.         float fov;
    4.  
    5.         // I'd like to do something like this
    6.         float dollyCartSpeed = gameObject.GetComponent<CinemachineDollyCart>().speed;
    7.  
    8.         if(_isBreaking) {
    9.             dollyCartSpeed = _breakSpeed;
    10.             fov = defaultFov / zoomMultiplier;
    11.         } else if(_isBoosting) {
    12.             dollyCartSpeed = _boostSpeed;
    13.             fov = defaultFov * 1.3f;
    14.         } else {
    15.             dollyCartSpeed = _defaultSpeed;
    16.             fov = defaultFov;
    17.         }
    18.  
    19.         ZoomCamera(fov);
    20.     }
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,658
    gameObject.GetComponent<CinemachineDollyCart>().m_Speed = bla
     
  3. monahajt

    monahajt

    Joined:
    Nov 28, 2017
    Posts:
    15
    ah, thank you. I had tried that but did it wrong initially, so thought that wasn't the correct way. I went back and tried and it works. Bam
     
    Gregoryl likes this.