Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice
  3. Dismiss Notice

Question Getting Cinemachine to follow a path

Discussion in 'Timeline' started by Shadowing, Mar 22, 2024.

  1. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    I can't figure out how to get Cinemachne to follow a path.
    I made the path but idk.
    Can't find a single video showing how to do this. Videos showing everything else but that lol.

    Can someone help guide me or locate a video for me.
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    You need to set the Body section of your vcam to "Tracked Dolly".
    Then, open up the foldout and set the Path field to point to your path.
    You can then manipulate the "Path Position" field to position the camera where you want it on the path. Before doing that, you should set the "Position Units" field to something useful (Normalized is a good one).

    upload_2024-3-25_11-14-36.png

    How would you like the camera to move along the path?
     
  3. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    Thanks man I got it working the other day.
    Next thing is I have a rabbit with a running animation with no root motion.

    Using a animation track I have him running in place.
    Whats best way to get him to move forward?

    I tried record using a cinemachine track and dolly with smooth path. But he only moves when I slide the time line back and forth. If u hit play on time line it won't move as well as entering runtime.

    Tried using record but doesn't seem to be good workgkow keeping toon from stuck to the ground
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    I don't understand. Why would putting the camera on a dolly track move the rabbit?
     
  5. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    I'm not wanting to. I can't find another way to move the rabbit along a path where it uses timeline forward and reverse etc. So hard finding documentation on this too.

    Only thing i can find is moving a humanoid with root motion using record feature.
    The record feature would work to I guess but it take for ever making sure the rabbit stays perfectly on the terrain on hills etc..
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    I think you want CinemachineDollyCart. It's behaviour whose job it is to move its GameObject along a path. So get rid of the camera and use a dolly cart instead.

    I don't know what you mean by timeline forward and reverse. If you want the rabbit's position to be controlled by Timeline, then record an animation for DollyCart.Position.

    I'm surmising that the question you're asking is how do you do the opposite of root-motion, i.e. drive the animation speed based on the character's displacement rather than the other way around. Am I correct?
     
  7. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    lets start over lol.
    On the rabbit I have Cinemachine Dolly Cart with a Cinemachine Smooth Path assigned to it.
    When I change the Position, the rabbit moves along the path.

    When I hit play on time line it doesn't though or if I enter runtime the rabbit just stays still.


    Now I have a virtual camera with Dolly Cart and it works fine
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    Thanks for the clarification. DollyCart doesn't execute in Edit mode. You have to be in Play mode. Virtual cameras, on the other hand, do execute in Edit mode.

    One possible workaround: make a custom version of DollyCart that executes in Edit mode. Just duplicate the code into your own script (it's very small).
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    Do you have an animation track on the timeline that is animating the cart's position?
     
  10. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    Ya I do thats how im getting him to animate jumping/running
     
  11. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    Ok so ya it does follow the path during runtime when I remove animation track.
    So my new problem is how do I get it to animate it running.

    I came up with an idea but I couldn't seem to get to work where I animate it running and then hit record while moving the position on the path.
     
  12. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    I'm having a really hard time following what you're saying. Please slow down and take the time to be specific.
    Which animation did you remove? The rabbit animation or the cart position animation?
    Did you have root motion enabled on the rabbit animation?

    huh?
     
  13. Shadowing

    Shadowing

    Joined:
    Jan 29, 2015
    Posts:
    1,649
    I removed the animation track that had the run animation on it.

    what is the cart position animation? I don't see that option.

    Root motion on or off makes no difference


    maybe its just as simple as creating a animator controller and have run set in a loop.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,834
    One way to handle this is to make an animation controller on the rabbit, driven by a state machine with walking/running/idle/jump states. You can then have a script that drives the state machine procedurally by keeping track of how fast the rabbit is moving, and setting the state accordingly (including animation speed - which you can tune to your animation to keep the feet from sliding).

    The beauty of doing it that way is that the animation doesn't care how the rabbit is being moved (whether it's from a timeline, or DollyCart, or custom script, it makes no difference).

    If you want an example of this, you can look at the sample scenes that ship with CM3 (if your project is CM2, start a new project with Unity 2022.3 or up, install CM 3.0.1, then install the 3D samples and look at the SImplePlayerController and SimplePlayerAnimator scripts). Look at any of the scene that use the animated character (e.g. FreeLook Deoccluder, or ClearShot).