Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. We have updated the language to the Editor Terms based on feedback from our employees and community. Learn more.
    Dismiss Notice

Question Custom(?) Dolly track

Discussion in 'Cinemachine' started by zeroneon, May 31, 2022.

  1. zeroneon

    zeroneon

    Joined:
    Dec 25, 2021
    Posts:
    5
    I would love to use a Dolly track but have it follow an object differently than it does usually. Usually, the camera on the dolly track follows the target even if the camera isn't the one with the highest priority. What I would like the camera to do is: sit idly on the track until it has the highest priority and from then on, follow the target using the target's position as the pivot point.
    I tried to visualize it the best I could in the attached image. I am wondering if there is a setting in cinemachine that would enable this specific behaviour or something similar
     

    Attached Files:

  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    you can turn off the automatic following by setting vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_AutoDolly.m_Enabled = false.
    When the camera activates, set it to true.
     
  3. zeroneon

    zeroneon

    Joined:
    Dec 25, 2021
    Posts:
    5
    I've gotten that far already sadly. I am trying to make the camera on the dolly NOT snap to the position of the player as soon as it gets enabled. As soon as it is enabled, I want it to check the position of the target object and use the Current target's position as a sort of pivot-point.

    Here is an example: The camera is in the middle of its dolly track, but the target is at the most left part of that track. As soon as it gets enabled, the camera immediately tries to move to the player as closely as possible.

    The behaviour I am trying to get however is that the camera stays in the middle and only moves on its dolly track when the player moves AS IF the camera is already dead on the target.

    So the behaviour would be something like this:

    Camera is at X = 10, Y = 0, Z = 0 with the dolly track starting at (10 | 0 | 0) and ending at (30 | 0 | 0)
    Target is at X = 20, Y = 0, Z = 0
    So now, the player moves 1 unit in the X-direction, leading him to be at X = 21

    NORMALLY the camera would move to X = 21
    But I would want it to move to X = 11 because the player only moved 1 unit in the X-direction
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,267
    Ah, I understand what you're trying to do. Thanks for the description.

    You would need to set the TrackedDolly's Auto.Dolly.PositionOffset at the moment the camera is enabled. To do this, you would find the closest point on the path to the target (using path.FindClosestPoint()). Then, convert the result to the units being used by your TrackedDolly component (using path.FromPathNativeUnits()), and set PositionOffset to be the difference between that and the vcam's current path position. That offset will then be maintained by the vcam as the player moves around.

    You can add an OnCameraLive handler to the vcam to execute this code whenever the vcam goes live, or you can do it directly in the code that activates the vcam.