Search Unity

  1. Improved Prefab workflow (includes Nested Prefabs!), 2D isometric Tilemap and more! Get the 2018.3 Beta now.
    Dismiss Notice
  2. The Unity Pro & Visual Studio Professional Bundle gives you the tools you need to develop faster & collaborate more efficiently. Learn more.
    Dismiss Notice
  3. Let us know a bit about your interests, and if you'd like to become more directly involved. Take our survey!
    Dismiss Notice
  4. Improve your Unity skills with a certified instructor in a private, interactive classroom. Watch the overview now.
    Dismiss Notice
  5. Want to see the most recent patch releases? Take a peek at the patch release page.
    Dismiss Notice

Using Cinemachine Dolly path in v2.0

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

  1. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    While the documentation is being finished, I thought it would write a quick post on how to use the new Dolly path feature in Cinemachine v2.0

    It allows you to create a very smooth path for the camera to go down and you can animate the speed or have the camera 'Auto follow' the subject. You can even auto follow the subject and animate a little offset so the camera goes a bit further ahead or behind, driven by a curve in Timeline. Neat!

    Install Unity 2017.1b3+ You must be above beta 3

    Install Cinemachine 2.0 There's a link to v2.0 from the v1.1 on the Asset Store too.

    If you into fantastic postfx, get the Post Processing Stack

    Open your scene and Intialize Cinemachine by going Cinemachine->Create Virtual Camera from the top toolbar. You'll see that a CM 'Brain' is created on the main Unity camera. This is where all the camera mojo happens and it has some global settings.

    Create an empty object in your hierarchy. Call it 'CM dolly path of wonder'

    Add the CM Path component. Search Path.
    upload_2017-5-17_17-25-1.png


    Add some waypoints. Note you can add more later, delete and even rearrange them.
    Note I increased the values of X for each waypoint.
    upload_2017-5-17_17-26-58.png

    You can also adjust the path in the scene view. The extra set of handles per waypoint are the tangent handles.
    upload_2017-5-17_17-28-47.png


    Now select a CM virtual camera. Set the 'Body' to be Dolly and drag your new path object into the path slot.
    You probably want the camera to Look At something and if you want to use the Auto Dolly, then have it Follow something too
    upload_2017-5-17_17-33-22.png

    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

    Animating Path Offset gives you control of being a little ahead or behind, etc.

    Boom!
     

    Attached Files:

    Last edited: May 17, 2017
  2. laurentlavigne

    laurentlavigne

    Joined:
    Aug 16, 2012
    Posts:
    1,959
    Look at them gizmos - nice!
    Can path component be used for other things? Like moving enemies in a SHMUP for example?
     
    Alverik likes this.
  3. Alverik

    Alverik

    Joined:
    Apr 15, 2016
    Posts:
    367
    Awesomeness! thanks for this. It's something I've been wanting for a while and it works really nice :)
     
  4. ArthurT

    ArthurT

    Joined:
    Oct 26, 2014
    Posts:
    67
    That's fantastic! Wasn't even aware there was a Dolly path feature implemented in CM 2.0.
    I would like to suggest the ability to set the current editor camera position and rotation into the selected path for quicker set up.

    Unrelated, I think it would beneficial for all of us if it's a possibility for the Cinemachine codebase being on Github, where any of us could do a PR to make improvements where needed. :)
     
  5. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    @ArthurT there's even more lurking in CM 2.0 which people don't yet know about. The documentation task is rather enormous.

    Github.. Lots involved with that idea. Eventually CM will be delivered by the Unity Package Manager. You might make an improvement but someone else may not and we'd become code reviewers and gatekeepers. There's a lot of touchy stuff in there which has crazy knock-ons which one might not expect.

    Think of all the systems and the order of operations. We auto compose on some target, then there's the dutch rotation, then there's the noise, then the subject goes over top which would make for gimble-lock hell while blending to a totally different camera setup - yet it all works. Touching just one of those systems can cause weird results in places you wouldn't expect, we've seen it many times and we're the ones who made it.

    That said, if you've got ideas on improving something, please let us know or try the change locally and let us know how it goes.
     
    Alverik and laurentlavigne like this.
  6. caixiang

    caixiang

    Joined:
    Dec 2, 2016
    Posts:
    4
    can we configure rotation on cinemachine path node, not only position?
     
  7. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    Hi @caixiang CM dolly path is a 'Body' component, which means that it just moves or translates the camera. 'Body' components only to translations, 'Aim' only do rotations. We've separated these two systems for a number of reasons.

    So if you want to configure rotation, use an appropriate Aim method:
    - Hard Constraint Look at a fixed point in the world, or keyframe animate the camera's aim
    - Composer Pick a target and let Cinemachine do the animation based on your compositional direction !
    - Group Composer Target a group of objects - you need to target a Group Target Camera object for it to work

    upload_2017-7-5_14-1-17.png

    Note - these examples are from Cinemachine v2.0 - https://www.assetstore.unity3d.com/en/#!/content/79898 which works in Unity 2017.1
     
    Alverik likes this.
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    @caixiang Sorry for the delayed response - I was on vacation and just came back.

    Although rotation is an Aim function and not a Body one, we have made a special exception in the case of TrackedDolly. If your vcam is on a dolly, but has no LookAt target, the camera orientation can be taken from the path. This is how you would set up a rigid camera on a track. Just set the TrackedDolly.CameraUp parameter to "Path", and the camera will take its orientation from the path. Each path node has a "Roll" field which, in conjunction with the path tangent and world up, is used to calculate local path orientation.

    If your vcam has a LookAt target, then the Aim component will override the camera orientation set by the TrackedDolly component.
     
    laurentlavigne likes this.
  9. hensoup

    hensoup

    Joined:
    Jan 13, 2014
    Posts:
    31
    hmm what about multiple dollies? for different paths?
     
  10. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    The best way to do that is to set up multiple vcams, each with its dolly path. Blend between them to switch paths. Adam showed this in one of his Cinemachine demos.
     
    Last edited: Aug 23, 2017
    Alverik likes this.
  11. vincismurf

    vincismurf

    Joined:
    Feb 28, 2013
    Posts:
    31
    I am testing cinemachine in 2017.1.0p2, and I noticed 2 problems
    1) AutoDolly does not expand or work.
    2) The CinemachinePath appearance does not expand either.

    --Correction in a raw project it work fine but my existing project had issue. I am guess someone broke the EditorDrawer logic
     
    Last edited: Aug 4, 2017
  12. hensoup

    hensoup

    Joined:
    Jan 13, 2014
    Posts:
    31
    thank you that is working
     
  13. deekpyro

    deekpyro

    Joined:
    Oct 16, 2012
    Posts:
    54
    How do you get access to a VirtualCamera's dolly component via code? vcam.GetCinemachineComponent<TrackedDolly>() doesn't seem to do it.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    You have to use the full class name:
    vcam.GetCinemachineComponent<CinemachineTrackedDolly>()
     
    Alverik likes this.
  15. Dreamrocket

    Dreamrocket

    Joined:
    Apr 27, 2015
    Posts:
    2
    Anybody can elaborate how to do this?

    "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"

    I am trying to animate my virtual camera body to make it move along the dolly path across time regardless of the position of its target. Should have been simple, but I have spent two days digging and dragging inside the unity editors.

    The last thing I'd like to do is change the source code to expose the Path Position, and write the animation code myself
     
  16. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Path Position is already exposed, and you animate it the same way you animate anything else from timeline:
    1. Create an animation track for you vcam (how? either create a new timeline for it, or drag it onto an existing timeline and select "Animation Track" from the popup that appears when you drop it).
    2. Hit Record on the new track (the little red button)
    3. Put the vcam in the inspector, and set a value for the path position, inside the "Tracked Dolly" section. This creates a keyframe at the current time (the field goes red to show that it's being controlled by timeline)
    4. Drag the timeline Current Time bar to a different time.
    5. Set a different value in the Path Position field in the vcam inspector. This creates another keyframe at the new time.
    6. Repeat for as many keyframes as you like
    7. Stop recording.
    8. You now have an animated dolly.

    upload_2017-8-23_8-1-53.png
     
    Laniemme and Alverik like this.
  17. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    @Dreamrocket this video shows it in action:
    as well as animating the composition of the camera while it's being pushed down the dolly track via Timeline
     
  18. Laniemme

    Laniemme

    Joined:
    Jun 11, 2016
    Posts:
    38
    I created my first Cinemachine and Time Machine combo today. The normal CM cameras work well, however, the dolly track doesn't do much. I did this:

    1. Created an empty object (called CM Dolly Path)
    2. Added Cinemachine Path script to it.
    3. Added waypoints (0,1,2,3).
    4. Dragged and repositioned the waypoints in my scene.
    5. Added CinematicShot clip to my Timeline
    6. Created CM camera.
    7. Dragged a gameobject to Look At.

    Any idea where I am going wrong? The first 2 camera shots (not dollys) work with no problem, then the dolly camera is switched to but does not move through the waypoints. Any assistance appreciated thanks.
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
  20. Laniemme

    Laniemme

    Joined:
    Jun 11, 2016
    Posts:
    38
    Thanks and sorry I forgot to add that step, yes I have the CM vcam1 body set to Tracked Dolly and the path is set to the waypoints object. I have Path Position at 0 so that the camera begins at the first waypoint at the start of the bridge. I actually used this thread (and Adams Unity Cinemachine video) to set it all up.
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    So you're animating the Path Position field and the camera isn't moving? What happens when you change that value manually?
     
    Laniemme likes this.
  22. Laniemme

    Laniemme

    Joined:
    Jun 11, 2016
    Posts:
    38
    Ok I have it now. I wasn't following each step of the animating dolly instructions. Thanks!
     
  23. Ray2016

    Ray2016

    Joined:
    Sep 13, 2016
    Posts:
    7
    Hello. I would like to know how to join the dolly. As if on a circular track?
     
  24. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    @Ray2016 In the inspector for the CinemachinePath, there is a "Looped" checkbox.
     
  25. Ray2016

    Ray2016

    Joined:
    Sep 13, 2016
    Posts:
    7
    brilliant! was wondering what that did!!!
     
  26. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    76
    Hi, it seems that the dolly track does not have a linear speed, it stops at each way point. Is that a normal behaviour ? How can this be fixed ?
     
  27. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    @Whatever560 - make sure you're on the latest version: https://forum.unity.com/threads/cm-v2-1-release-candidate.497202/

    There's a few ways to drive the dolly cam (or cart): through keyframing the path position or the velocity and with the Auto Dolly. It shouldn't stop at each waypoint unless you're in Auto-Dolly mode and the shape of your path has some points nearer the follow object which in turn will cause the camera to hang around there longer as it's just trying to follow the closest.
     
    Alverik likes this.
  28. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    @Whatever560 The track can make the objects slow down at the waypoints if the tangents are too small. Velocity is defined by the tangents, and is interpolated between the waypoints. If the tangent is zero at a waypoint, the following object will stop.

    In Cinemachine 2.1 (available here: https://forum.unity.com/threads/cm-v2-1-release-candidate.497202/) there is a new option when following a path that makes this problem go away: choose "Distance" as your path unit. Then the tangents will influence direction only, not velocity.
     
    Whatever560, Alverik and Adam_Myhill like this.
  29. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    Update - Velocity was an old term, it's been redesigned to be Distance/Speed.

    Greg's bang on about the tangents.

    You can use Cinemachine->Create Dolly Track and Cart
    Set it to Distance and key the speed.
    upload_2017-11-2_10-20-55.png

    The Cart is a way of animating an object which you can then apply a vcam to - or anything else! People are using dolly carts for all sorts of crazy animation things.
     

    Attached Files:

    Whatever560 and Alverik like this.
  30. Whatever560

    Whatever560

    Joined:
    Jan 5, 2016
    Posts:
    76
    Was using latest stable 2.0. Will try the next one once it's released. Thanks
     
  31. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    312
    @Whatever560 These are release candidates. They're safe to use. We're adjusting little things here and there but that shouldn't dissuade you from grabbing it. The 'released' version only means we put it on the Asset Store.

    There are significant improvements from v2.0 to v2.1. Definitely grab RC7
     
    Whatever560 and Alverik like this.
  32. george_00

    george_00

    Joined:
    Oct 23, 2015
    Posts:
    12
    @Gregoryl could you elaborate on this? How exactly do I set the TrackedDolly.CameraUp parameter to "Path"? I'm an artist using Cinemachine as an animating tool and I don't have scripting skills - is that what's needed here? Thanks!
     
  33. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
  34. george_00

    george_00

    Joined:
    Oct 23, 2015
    Posts:
    12
    Thanks!
     
  35. nordtribe

    nordtribe

    Joined:
    Oct 27, 2017
    Posts:
    2
    Hey im using the new Cinemachine Dolly Cart to animate movement. I have figured out how to provide at object with a new path via script, but it creates a stop in motion when changing. Is it possible to blend between path in some way?
     
  36. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    @nordtribe Set the Position Units to "Distance".

    upload_2018-1-11_14-8-45.png

    Edit: oh wait, I think I might have misunderstood your question. Are you swapping out the old path mid-movement and replacing it with another one?
     
  37. chrisflorio

    chrisflorio

    Joined:
    Nov 15, 2013
    Posts:
    3
    I am using 2017.3 and do not see the tangent handles on the dolly track that you described above. Are they still available and if so how do you access them? Thanks.
     
  38. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Cinemachine is an asset released on the asset store, and is not hard-coupled to Unity releases. In Cinemachine/About, you will see the CM version number.

    Newer releases of CM have two path implementations: CinemachinePath and CinemachineSmoothPath. SmoothPath is used by default and has automatic tangents, which guarantee second-order continuity of the path. If you want manual tangent control, you'll have to swap out the CinemachineSmoothPath component and use the CinemachinePath component instead. Then you'll see the tangents.
     
    Alverik likes this.
  39. chrisflorio

    chrisflorio

    Joined:
    Nov 15, 2013
    Posts:
    3
    Got it, thanks very much for the quick response, I appreciate it.

    Perhaps Cinemachine Path (with tangent controls) should be the default for Dolly Cart as it gives control that at least for me would normally be needed.
     
  40. biscito

    biscito

    Joined:
    Apr 3, 2013
    Posts:
    82
    hum, hi, we are working on a 2.5D platformer, and we are wondering how to lock or constrain the Z position on the camera? without a dolly, just a bool,

    any idea?
     
  41. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Try a CinemachineConfiner extension, using a flat box as a shape. Or, it's very easy to make a custom extension to do that.
     
  42. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    @biscito Here is a little script to lock the camera Z. Drop it in your project as LockCameraZ.cs, and a new "LockCameraZ" option will appear in the Cinemachine Extension dropdown.
    Code (CSharp):
    1. using UnityEngine;
    2. using Cinemachine;
    3.  
    4. /// <summary>
    5. /// An add-on module for Cinemachine Virtual Camera that locks the camera's Z co-ordinate
    6. /// </summary>
    7. [ExecuteInEditMode] [SaveDuringPlay] [AddComponentMenu("")] // Hide in menu
    8. public class LockCameraZ : CinemachineExtension
    9. {
    10.     [Tooltip("Lock the camera's Z position to this value")]
    11.     public float m_ZPosition = 10;
    12.  
    13.     protected override void PostPipelineStageCallback(
    14.         CinemachineVirtualCameraBase vcam,
    15.         CinemachineCore.Stage stage, ref CameraState state, float deltaTime)
    16.     {
    17.         if (stage == CinemachineCore.Stage.Body)
    18.         {
    19.             var pos = state.RawPosition;
    20.             pos.z = m_ZPosition;
    21.             state.RawPosition = pos;
    22.         }
    23.     }
    24. }
    25.  
     
    Alverik and biscito like this.
  43. biscito

    biscito

    Joined:
    Apr 3, 2013
    Posts:
    82
  44. chrisflorio

    chrisflorio

    Joined:
    Nov 15, 2013
    Posts:
    3
    I am trying to trigger events based on a dolly camera's path position. Can you tell me how I would access that property in code?

    Thanks very much.
     
  45. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    vcam.GetCinemachineComponent<CinemachineTrackedDolly>().m_PathPosition
     
  46. Snake111

    Snake111

    Joined:
    Mar 19, 2015
    Posts:
    13
    Hey I'm working on a game like Until dawn I can setup a Dolly track to follow my character but when he open a door and go on other room how can I make the transition from a dolly track to an other one?
    Is there a way to split the dolly track in a T shape?
    thanks
     
  47. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Have 2 dolly tracks, each with its own vcam. When you get to the end of track 1, enable vcam 2 and the camera will smoothly transition to it.
     
  48. Snake111

    Snake111

    Joined:
    Mar 19, 2015
    Posts:
    13
    With a basic script on enter trigger set active true?
     
  49. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    1,637
    Yes that would work.
     
  50. BinaryX

    BinaryX

    Joined:
    Aug 4, 2014
    Posts:
    51
    Hello,

    I was wondering, is it possible to have the camera not follow a "target", but follow the dolly track ?
    As an example i'm imagining a roller coaster in first person. The camera will always look "forward", but that forward will change according to the path's position and roll.