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

Using Cinemachine Dolly path in v2.0

Discussion in 'Cinemachine' started by Adam_Myhill, May 17, 2017.

  1. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    You can stop the timeline from making a hard cut by setting the ease in/ease out times on the clip. Giving a CM clip an ease-in time will cause the camera to blend from the current active vcam to the clip vcam, over the length of the ease-in. Similar for ease-out.

    upload_2019-1-17_7-49-45.png
     
  2. Studiomaurer

    Studiomaurer

    Joined:
    Sep 5, 2012
    Posts:
    56
    I found a workaround by eliminating the cinemachine track altogether, just animating the path value with timeline (I might as well lerp it by code, there is no reason to use timeline any more) and switch the VCAMS using the priority value. Losing the nice previewability of the flight, but it works. Still, this looks like a bug to me, this should work with a cinemachine Track...
     
  3. Studiomaurer

    Studiomaurer

    Joined:
    Sep 5, 2012
    Posts:
    56
    Oops, missed your post. Thank you...
     
  4. Adam_Myhill

    Adam_Myhill

    Joined:
    Dec 22, 2016
    Posts:
    342
    @BinaryX Cinemahine separates the ideas of translation, or body movement, and orientation - camera aiming.

    Auto dolly track will follow - move the camera - based on whatever you put in the follow slot. Look at is where the camera orients / aims at. That can be an entirely different thing. You can look at an object further ahead on the track, or the front of the car you're in or.. whatever.

    You could also put 'Do Nothing' in the Aim and have the camera hard locked to the cart and it will inherit all the cart's motion and always be 'looking forward'.

    Lots of options!
     
  5. Studiomaurer

    Studiomaurer

    Joined:
    Sep 5, 2012
    Posts:
    56
    @Gregoryl : I'm still somewhat puzzled, the blending is still behaving weird.

    Current Virtual Camera Setup:
    VC A: Start Camera, rotation dynamic.
    VC B: Tracked dolly cam aiming at a lookAt target
    VC C: Target Camera, also dynamic

    The endpoints of the dolly path exactly match the positions of VCA and VCC.
    I've set up a timeline that will blend from the start camera to the tracked dolly, animate the dolly ride and in the end blend to the target cam (I switched priorities inflight by code, but the same motion appears when I put the cameras on the cinemachine track) The blends basically only exist to adjust the rotation to the current dynamic positions at the end points.

    When I run the application the camera position goes crazy during the ease out blend, it looks like cm uses the starting point of the path for the blend instead of the current camera position) This does not happen when I scrub the timeline manually! I can't figure out what's causing this behaviour.

    Download a Screencapture (WMV)
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Can you enable the Debug Text on the Brain so we can see what cameras are getting enabled and when?

    When you change the priorities, CM is blending from vcam A to vcam B. The timeline is overriding that, but the blend is still happening under the hood. Depending on when you switch the priorities in-flight, you could be seeing the tail end of the blend vcam A to vcam B. An easy fix would be to add a custom blend setting that forces a cut when transitioning vcams A to B. Make sure you switch priorities after the timeline clip has faded in, but before it has faded out.
     
  7. Studiomaurer

    Studiomaurer

    Joined:
    Sep 5, 2012
    Posts:
    56
    Yes, that was it... I have LOTS of virtual cameras in the project. So instead of creating custom blends for any possible combination it was easier for me to take control over the CinemachineBrains default blend value from my CameraManager and switch it to zero during this kind of transition. But that did the trick, thank you.

    (Edit:By the way, the oder of the camera list for custom blends seems a bit random, alphabetically would be way better....with lots of Cams in the Scene it would have taken me forever to set up custom blends.)
     
    Last edited: Jan 21, 2019
  8. CSmochinaArnia

    CSmochinaArnia

    Joined:
    Feb 26, 2018
    Posts:
    7
    I'm manipulating the path position by code and don't use a timeline track. The only problem is, when I'm setting the path position to 0, from whatever it was left at, instead of snapping to 0 position, it interpolates there. How can I force it to snap to 0, or whatever path position I want it to?
     
  9. CSmochinaArnia

    CSmochinaArnia

    Joined:
    Feb 26, 2018
    Posts:
    7
    Found a way to force it. Disable the brain while setting it and enabling in a frame later.
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Or, perhaps cleaner, you can set vcam.PreviousStateIsValid = false.
     
  11. CSmochinaArnia

    CSmochinaArnia

    Joined:
    Feb 26, 2018
    Posts:
    7
    That is awesomest! Thank you
     
  12. Split3

    Split3

    Joined:
    Aug 21, 2017
    Posts:
    17
    Hey, I'm working with dolly track, can I make from 1 rail path, 2 path choices?
     
  13. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Paths cannot branch.
    If you want to branch, you need to make a second path and switch to it.
     
  14. Split3

    Split3

    Joined:
    Aug 21, 2017
    Posts:
    17
    How could I switch them by my player pos? Any ideas?
     
  15. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Maybe have a trigger collider somewhere. When player enters it, trigger calls your code to do the switch
     
  16. BitGamey

    BitGamey

    Joined:
    Jun 11, 2016
    Posts:
    52
    I created a 'dolly track and cart' where I need the vcam to face in the direction of the track shown in grey (think of a train driver holding a video camera). Due to this behavior, there is no 1 target to look at or follow. By default the camera is just facing the original direction it is set at for the whole duration of the track. I'm sure this is probably something simple, but I haven't found it yet.
     

    Attached Files:

  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    upload_2019-4-23_12-30-0.png
     
    BitGamey likes this.
  18. BitGamey

    BitGamey

    Joined:
    Jun 11, 2016
    Posts:
    52
    Thank you!
     
    Gregoryl likes this.
  19. ZAXIS

    ZAXIS

    Joined:
    Sep 30, 2016
    Posts:
    23
    Let's assume I have a net of different paths:
    upload_2019-8-19_12-52-1.png

    Would you advice anything smarter than checking every frame proximity to each of these paths and switching when it gets over some treashold? This would not scale well
     
  20. aerospacevitd

    aerospacevitd

    Joined:
    Nov 29, 2017
    Posts:
    5
    Can you use the cinemachine path to animate non camera game objects? It seems to not move any object I've put under a virtual camera.
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    That's pretty much the way to do it. You'll have to figure out a way to optimize this, perhaps with space partitioning, so that you can tune how often you check for proximity.
     
  22. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Yes. Don't put objects under the vcam. Use CInemachineDollyCart, which is a transform that can follow a path. Or roll your own, based on the code in CinemachineDollyCart.
     
  23. DirgaS

    DirgaS

    Joined:
    Jul 16, 2018
    Posts:
    1
    Hi,

    I just try using cinemachine recently and I want to make a track that following my rollercoaster track that have loop in the middle, but when I try to make the track following my track it become twisted. Is there a way to make the track doesn't get twisted like that? Thanks in advance.

    upload_2019-8-28_15-16-37.png

    upload_2019-8-28_15-19-4.png
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Adjust the waypoint roll

    upload_2019-8-28_8-39-21.png
     
  25. Tarrag

    Tarrag

    Joined:
    Nov 7, 2016
    Posts:
    215
    Hi, this doesn't work for me to get the cam position along the tracked dolly, can't find how to get what path the vCam is on:

    vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_PathPosition

    Can't attach Dolly Track to CinemachineTrackedDolly as component. Interestingly I don't get any log null ref either in console.

    I tried also with CinemachineSmoothPath, CinemachinePath to no avail.

    I couldn't work out from the documentation how to get current path position, can you please suggest, thanks a bunch,

    On Unity 2019.1.6f1, cinemachine 2.3.4
     

    Attached Files:

  26. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    You need one object which is the CinemachinePath (or SmoothPath). You have that.
    Next, you need another object which is a vcam with a CinemachineTrackedDolly component (you have that too).

    Then you connect them by adding a reference to your path in the CinemachineTrackedDolly component:
    Code (CSharp):
    1. vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_Path = myPath;
    You get the path position like this:
    Code (CSharp):
    1. float pathPosition = vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_PathPosition;
     
  27. LezCT

    LezCT

    Joined:
    Nov 15, 2014
    Posts:
    55
    Hello, I need to change the dolly cam's Camera Up - Path Direction to Look at the left/right path direction instead of the default/current one that is on the forward path direction. I don't want to use the Composer to avoid unnecessary rotations. it's for a 2.5d game I'm making. is that possible? upload_2019-9-5_10-41-25.png

    [UPDATE] I think i got it, but I'm not sure if i'm calculating it right, but so far it works for my needs.

    Code (CSharp):
    1.         public Vector3 RotationOffset;
    2.  
    3.         protected override void PostPipelineStageCallback(CinemachineVirtualCameraBase vcam, CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    4.         {
    5.             if (stage == CinemachineCore.Stage.Body)
    6.             {
    7.                 state.RawOrientation *= Quaternion.Euler(RotationOffset);
    8.             }
    9.         }
     
    Last edited: Sep 5, 2019
  28. hipstermia

    hipstermia

    Joined:
    Jul 15, 2019
    Posts:
    1
    "If you're not going to use Auto Dolly, then animate Path Position any way you want. It animates really nicely from Timeline, just drag the virtual camera onto Timeline and say Animate"

    what do you mean by animate? I'm having issues finding an "animate" button
     
  29. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    In timeline, create an animation track for the cart, hit the "record" button on the track (the little red circle), and set keyframes for the cart position.
     
  30. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Hello! In unity 2019.2.10f1 , dolly camera on track dosent follow the path... Sometimes it goes below or toohigh.. offsets are 0,0,0.. wich I believe mean stay excactly on track? @Gregoryl
     
  31. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    @mattis89 We have not seen anything like this. Can you show inspectors with your settings? A video of the problem would also be helpful.
     
  32. mattis89

    mattis89

    Joined:
    Jan 10, 2017
    Posts:
    1,151
    Fixed
     
  33. quix22

    quix22

    Joined:
    Sep 6, 2018
    Posts:
    16
    This is a very nice project, and I'd like to try out something like this too. Is there a way to add a material to Cinemachine? I noticed earlier in the thread that @DirgaS has modelled a track with a loop and the concept seems to be overlay the Cinemachine track slightly above the modeled track. Is the track modeled in something like Blender and imported into Unity?
     
  34. subhaJit_Dev

    subhaJit_Dev

    Joined:
    May 28, 2015
    Posts:
    1
    Hi,
    Thank you for creating such a useful component. I have a few questions, if you could answer.
    a. Can a cinemachine tracked dolly with path be created at runtime?(the user clicks on the screen to set the waypoints for the path)
    b. Can the same be done with a cinemachine dolly cart attached to an object?
    Thanks.
     
  35. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    a. Yes. Look at CinemachineSmoothPath.cs to see how it works. You'll have to manage the m_Waypoints member with your code. It is also possible to create your own custom path type - just derive it from CinemachinePathBase class, and you can use it with other parts of CM.
    b. Yes. The path is an independent thig. The CMDollyCart and the CMTrackedDolly both are observers of a path. If you make code to dynamically generate paths, you can use it with either one.
     
  36. batman2211

    batman2211

    Joined:
    Sep 16, 2017
    Posts:
    10
    Should I use this feature to make a traffic system where vehicles follow a path?
     
  37. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    You could, but I would need more details about your use-case before making any specific recommendation.
     
  38. novajunction

    novajunction

    Joined:
    Dec 7, 2017
    Posts:
    3
    I'm creating a fly-through system where the vcam is following one dolly, and looking at another (which you explained in a separate reply), and I'm struggling to figure out how to pause the dolly at specific waypoints for set periods of time before continuing along the track. The code I've written so far disables AutoDolly based on path position, but it's not disabling it in the editor. Any help you could give would be awesome.
     

    Attached Files:

  39. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Are you trying to just animate along a path, with pauses at the waypoints? If so, then you shouldn't be using auto-dolly. Otherwise, can you explain in more detail why you need auto-dolly?
     
  40. novajunction

    novajunction

    Joined:
    Dec 7, 2017
    Posts:
    3
    Client wants to have the ability to adjust parameters for each event that may or may not occur once the build is delivered, and this could include where and when the camera stops. I suppose I don't NEED Auto Dolly, it was just the easiest way to get things running with other elements in the game.
     
  41. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    You could have an invisible game object inside a dolly cart that's riding the path. You can make a custom script to animate its path position in any way you like, according to some data that's read at runtime (consisting of points along the path, when to reach them, how long to pause there - i.e. rich keyframes). Then you can have the vcam follow that object with auto-dolly. No need to ever turn auto-dolly off.
     
  42. novajunction

    novajunction

    Joined:
    Dec 7, 2017
    Posts:
    3
    Thanks for the help!
     
  43. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    I want to stop and re-start the dolly based on its position. I'm accessing m_Position in the CinemachineDollyCart but it doesn't seem to be working.
     
  44. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    If the cart's m_Speed is nonzero, then it will update its own position every frame, and overwrite what you put. Set m_Speed to 0 when you want the cart to stop.
     
    MathewHI likes this.
  45. MathewHI

    MathewHI

    Joined:
    Mar 29, 2016
    Posts:
    501
    Thank you sir.
     
  46. gurbrindersingh

    gurbrindersingh

    Joined:
    Feb 28, 2017
    Posts:
    32
    I am moving an object as child of dolly cart and using CinemachinePath for track. Path takes left and right turns. For some reason object pauses a bit at every waypoint. It feels really jerky and unsmooth. How can it be smoothened. (using version 2.6.5)
     
  47. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    It's because your cart is using Path Units. Change it to Distance Units.
     
  48. gurbrindersingh

    gurbrindersingh

    Joined:
    Feb 28, 2017
    Posts:
    32
  49. gurbrindersingh

    gurbrindersingh

    Joined:
    Feb 28, 2017
    Posts:
    32
    Here is my setup

    upload_2021-6-10_17-32-44.png


    upload_2021-6-10_17-33-18.png
     
  50. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,624
    Yes, I see it. Can you show me the path? (scene view, please, with the waypoints clearly visible).
    If the project is small, you can zip it up and send it to me. That might be more efficient.