Search Unity

Path Position Versus Distance

Discussion in 'Cinemachine' started by Multithreaded_Games, Dec 18, 2017.

  1. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    Hi all,

    I have a dolly track camera that has an animation that increments the Path Position variable to move the camera along the track. When I use Path Units, as expected, the camera speeds up and slows down depending on the relative distances between its current and next waypoint. I was hoping, however, that I could use Distance, but it seems to be an actual world-unit distance and not a 0 ...1 distance as I was hoping.

    Since there is no easy way to tell how long the path is, it's a bit frustrating trying to have the camera track with consistent movements (IE moving at a constant speed), since I have to guess and check for the right ending path distance. Am I going about this the wrong way? Would it be possible to, at least, add something that calculates the total distance of the path and displays it (perhaps in the Dolly Track object itself?)

    Thanks!
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    You can get the length of the path:
    Code (CSharp):
    1. CinemachinePathBase path;
    2. float length = path.PathLength;
     
    HeyBishop likes this.
  3. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    @Gregoryl,


    Thanks for the lighting-fast response! I figured this was possible via script, but since I'm changing keyframes in the Timeline editor, it'd be nice to see what the value is--IE, it might be a nice addition to the Path's inspector. I'll go ahead and make the change on my end for convenience. Thanks!
     
    Gregoryl likes this.
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    @Multithreaded_Games Thanks for your feedback. We've added a Path Length display to the inspector, and also took the opportunity to add a "Normalized" option to the Position Units selector in the Tracked Dolly component. Using this setting, the path position ranges from 0 to 1.

    upload_2017-12-19_16-13-16.png
     
  5. Multithreaded_Games

    Multithreaded_Games

    Joined:
    Jul 6, 2015
    Posts:
    122
    @Gregoryl

    Thanks so much for implementing this, appreciate it!
     
  6. bourriquet

    bourriquet

    Joined:
    Jul 17, 2012
    Posts:
    181
    @Gregoryl Normalized means Distance Normalized, right? Because it could also be Path Units Normalized.
     
  7. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    Yes, normalized distance
     
  8. sking995

    sking995

    Joined:
    Mar 22, 2021
    Posts:
    26
    Is there anyway to turn a position (float) in from pathUnits to normalized units?
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,723
    You can use path.FromPathNativeUnits() to convert from PathUnits to normalized.
     
    sking995 likes this.