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
  3. Join us on November 16th, 2023, between 1 pm and 9 pm CET for Ask the Experts Online on Discord and on Unity Discussions.
    Dismiss Notice

Jerky horrible movement with CineMachine on a path

Discussion in 'Cinemachine' started by misterlee, Sep 24, 2017.

  1. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    I'm trying to make a simple camera follow the player along a path using the 'dolly track'.
    I've set the path and camera up, it's following the object I set, it's very straightforward, I'm not doing anything unusual, but the camera movement it terrible. As soon as the camera nears a waypoint on the path it jumps ahead along the path by a lot. The camera movement was smooth up to then, but as soon as it gets near a way point it jumps ahead, and then it's also not in line with the thing it's meant to be following either. Anyone know why this is and how to fix it?
     
    unity_Jv7b1IB9-5ETfw likes this.
  2. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    342
  3. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Thanks, but yes it's exactly the same. Still very jerky movement near waypoints. The camera is also almost never in line with the thing it's meant to be following, even though it's set on 'hard contstraint' which to me sounds like it should be exactly in line. It's either way ahead or way behind the target.
     
  4. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    342
    The aim or body is set to hard constraint? The body should be set to Tracked Dolly

    Try a little Z damping,
    Search Radius to 0
    Search Resolution up higher.

    It's smooth... if the problem persists, sending over a stripped down example scene will help us debug it.
    upload_2017-9-24_10-45-5.png
     
    altair2020 likes this.
  5. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    I've been trying it in the scene view rather than in play mode, it seems to be slightly better in play mode, i.e. when the game is running, than when I was testing it in the scene view. But it's still a noticable jump when going between waypoints, particularly when starting a downward slope from a previously flat area.


    edit - I think we were replying at the same time :) I'll try those things you mentioned....
     
  6. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Unfortunately still the same. Very jerky and way off the target object :(
     
  7. Adam_Myhill

    Adam_Myhill

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    342
    Very strange. We need a demo scene to test - if you could send one over we're happy to diagnose this for you. Or an example video would be great.
     
  8. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Ok thanks, if a video would be be ok that would be a lot easier to make. Where should I send it?
     
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    @misterlee could you post a snapshot of the inspector for your jerky vcam? The whole thing please
     
  10. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Sure...

     
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    @misterlee There are a three things that I can see off the top:
    1. You're using Distance units. For Auto-dolly, there is no need for Distance Units, and Path Units have better precision.
    2. Your waypoint tangents are zero or close to it. This hurts your precision when using Distance Units, especially around the waypoints.
    3. Your search resolution is 1. Again, bad for precision. Put it higher, say between 5 and 10.

    I would suggest a 4th thing too. Since you've upgraded to the latest CM, try replacing the CinemachinePath component with the new CinemachineSmoothPath. You'll have to re-enter the waypoints, but I think you'll be pleased with the results. Let me know how it goes.
     
  12. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Thanks for the info. The settings I had in that screenshot were the result of trying to change things to solve the problem that the default settings caused, so I was changing all the settings to see if anything would help. I tried what you suggested, it's pretty much exactly the same result. Still very jerky movement near waypoints and the camera gets far off from the target in some places along the path.

    The smooth path component was actually much worse than the regular one. As well as doing the jerky movement and not being aligned with the target, it was creating it's own curves to smooth between the points and taking the camera off where I didn't want it to be.

    Having played with the tangent values a bit I'm guessing what it's doing is to the divide the path into sections and then move the camera from one section to the next, but it's not making even sections so the movement is not even. There are more sections, closer together where there is a curve and fewer on the straight parts, which makes sense from an optimisation point of view, but not for the smooth movement of the camera. It goes slower on the straight parts and fast on the 'bends' because the path is unevenly subdivided, which is probably why it gets further away from the target too. The player (target) is almost off the screen in some places, and it's only a short section of tunnel I'm trying to walk along.
     
  13. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    I did make a video of what's happening, but of course youtube is as useful as an inflatable dartboard so it doesn't work. I might try again tomorrow, but I've already wasted an entire day with absolutely nothing to show for it.
     
  14. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    @misterlee We haven't seen anything like what you're describing. I'll have to see a video, or better yet, a trimmed-down project that shows the problem, if you can manage that.
     
  15. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Ok the video is working now...

    I was walking really slow in the video at the start to show how the camera jumps forward, and then you can see it goes far in front of the target. Does that help at all?
     
  16. JakubSmaga

    JakubSmaga

    Joined:
    Aug 5, 2015
    Posts:
    417
    Looks like your video is unlisted/private.
     
  17. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    I think your video is private... can't access it.
     
  18. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Sorry! It's really not my day today is it?! I set it to unlisted, I think you should be able to see it now?
     
  19. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    I saw the video (thanks), and I think I might know what's going on. To be sure, I'd need to see a top-down in the scene view, showing the entire path and the character, but what it looks like is this: I think you might have a concave path around the moving character, which makes it difficult to get a nice motion from the auto-dolly algorithm, which is based on sending the camera to the point on the path that's closest to the character. As the character walks, he takes a short cut across the arc, and the closest point jumps suddenly from one part of the path to the other, and the camera jumps too.

    It's not about nearness to a waypoint, or about how the path is subdivided, or anything like that - it's about the shape of the path. As an extreme example, think of your character standing at the exact centre of a circular path. Where is the closest point? If the character sways even slightly, the camera will shoot erratically from one side of the path to the other. So if that's indeed what's happening, you need to rethink the shape of your path, or if you really want to keep the concave path, you have to animate the camera position in a different way.
     
    Last edited: Sep 25, 2017
  20. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Thanks for the explanation, I'm sure that's exactly the issue. The tunnel slopes downwards at the start, so yes that section could be considered concave if you're looking at it from below, but the camera is above so maybe not?

    It's a horizontal movement, so a top down view wouldn't help, but I made a screenshot to show you...



    After doing this I experimented with the location of the path. Originally I put the path where I wanted the camera to be. I tested putting it on the ground where the character walks and adding an offset to the camera. The top of the slope is much smoother, but now the problem occurs at the bottom instead, and the camera is still very much not aligned with the target while on the slope. So that pretty much confirms it has problems with a concave shaped path. So basically this camera path system is only going to be useful for games on a flat surface, in a straight line, which doesn't seem very useful at all tbh.

    Maybe I'll have to set up two or more separate paths, one on the flat sections, and then one on the slope and have the camera move or blend between them... something like that might work? It seems like a lot of extra effort for what is really a very common scenario in a game environment. Going down a slope must be extremely common in games so I'm sure many people will end up having a similar issue.
     
  21. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    So you have 2 issues:

    1. the camera jumping forward as it rounds the corner.
    2. the character not appearing aligned with the camera toward the bottom of the path

    The first is due to the path shape, which is indeed concave from the point of view of the target.

    For the second issue, I have to ask you what you mean by "aligned". Do you mean the camera must be at the point on the path that's closest to the character? I am quite confident that it is. That's what auto-dolly does, up hill or flat or down. Do you mean that the character must be centred in the screen? If so, then my next question is: what is the LookAt target of the camera? In the snapshot you sent earlier, there was no lookAt target, i.e. the camera was not being told to look at anything. Dolly is a Body function, and as such is responsible for setting the location of the camera. It positions the camera relative to the Follow target. If you want also to point it at something then you have use the Aim component, which uses the LookAt target. Set that to the character as well.

    I have another question for you. You seem to want the camera to look at and follow a character, at a certain offset from it. Is Dolly and track the best and most flexible way to do this? Could you not instead position the camera using a transposer at a fixed offset, with damping? That way you wouldn't need to define a track at all.
     
  22. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    Exactly yes, those two things. By aligned I meant that the target/player would be centered in the camera all the way along the path, as it was at the start. The reason I don't use the look at target is because that will cause rotation on the camera which I don't want.

    I made an illustration to show what I thought would happen vs what seems to be happening. 1 is what I was expecting, 2 is what seems to be happening. The blue line represents the path, the green is the camera, yellow is describing where the camera is on the path/relative to the path. Does this make sense or am I just guessing/interpreting it wrong?



    In the end I've realised using a camera path is not going to work for me, so I'm using a '2D' camera (it's constrained to the X and Y axis) instead. I thought the path would be ideal for this scenario because it's quite a narrow, contained space that the player can move down in one direction, which seemed exactly what a camera path would be good for but in the end it's not so much, at least not how it currently works with curved paths.

    p.s. I didn't see a way to do the cinemachine camera constrained to X Y axis, so I'm using a different asset. Is there a way to do that?
     
  23. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    Yes 2 is the expected behaviour. The path offset (your yellow line) is always path-local (i.e. defined by the path tangent at the camera point), not world-space.

    I think you're on the right track (no pun intended) with the 2D camera. You can do it very nicely in Cinemachine with the Framing Transposer Body component. This will move the camera, without rotating it, to get the framing that you specify. The relationship to the target is defined by the virtual camera transform's rotation, which will be preserved, and a desired distance that you set.
     
  24. misterlee

    misterlee

    Joined:
    Sep 19, 2014
    Posts:
    54
    I love being on track with my cameras! :D

    The transposer component moves in all 3 directions though doesn't it? So it will go in depth (Z) too, where as I want it to only move in the X and Y axis. I couldn't see any way to constrain it, but maybe I missed that somewhere.
     
  25. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,240
    The Z will be effectively constrained by the camera angle, the desired distance you set, and the character's motion. However, if the character is going to move in Z, but you want the camera to remain in the XY plane, you can achieve that by adding a Confiner extension to the vcam. Wire it up to a slim box on the XY plane and the camera will stay in it.
     
    BCFEGAmes likes this.