Search Unity

Resolved Jittering with Target Group?

Discussion in 'Cinemachine' started by Gyro_Zeppeli, Apr 20, 2022.

  1. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    Hi, I've created a targeting system in my project, that switches camera when the targeting button is pressed.

    It switches from a FreeLook to a Virtual Camera that uses a dynamically updated target group to keep both the player and the target in the frame. It should keep the target around the center of the screen while the Player moves around it.
    As you can see in the video, it works but jitters a lot while the Player moves around the target.

    YT link:


    Unity Ver: 2021.1.19
    Cinemachine Ver: 2.8.4

    I uploaded the current settings I'm using with the cinemachine and target, tried to change everything I could think of but to no avail.

    Also, if it can help, Player is using a characterController and moves in Update().

    Cinemachine Brain has Smart Update on.

    Thanks!
    Cinemachine1.PNG Cinemachine2.PNG
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    That kind of jitter is usually caused by FixedUpdate vs Update inconsistencies. Are you sure that 100% of your movement happens in Update()? No RigidBodies?

    That said, there is an easier way to get this camera behaviour. Set up your vcam like this:
    Body: Framing Transposer, FollowTarget = player
    Aim: Composer, LookAt target = target

    You don't need a target group.
     
  3. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    Yeah, there are no rigidbodies in the scene at all, all the movement logic is done in Update().

    However, changing the code to what you advised made the situation much better, but the jittering is still somewhat present. It's much better in build, so I'm thinking maybe it's something performance related?

    I'll try to play a bit with the values and try to figure out what's happening :(

    Thanks for the tip, I'll keep this thread updated if I can't solve the issue.
     
  4. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    I tried putting the movement code in FixedUpdate() and forcing the Update Method in the brain to FixedUpdate, and this solves the issues. However this can't be a permanent solution cause I need the character controller to move in Update.
    It really doesn't make sense, the target is just a static object with no rigidbody or anything.
    At least we know it's related to update inconsistencies I guess?
     
  5. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    More footage here
     
  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    If putting everything in FixedUpdate solves the issue, then it's likely that you have some component of your movement happening in FixedUpdate, or if not, then somewhere your movement code isn't taking Time.deltaTime properly into account.
     
  7. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    Yeah, you were right, I was multiplying Gravity by Time.DeltaTime twice! Thanks for the help
     
    Gregoryl likes this.
  8. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    Okay, turns out that the problem went away only for a day and it happened again the day after.
    (Almost certainly it never went away, I was probably just trying with high framerate and it was less noticeable).


    So, to get the bottom of this (since my project is very complicated) I created a totally new project and managed to replicate it.

    What I've done is:
    -Created an object with a CharacterController (no rigidbodies)
    -Move the Character in Update(), reading the rotation of the camera and applying it to the movement to move according to camera.
    -Replicated the targeting camera with the the Player as the Follow and the Target as the Look At

    The result is that the camera jitters a lot.
    The ONLY time I'm multiplying the movement by Time.DeltaTime is in Update once, like the documentation says and this is needed to not have frame dependent movement.

    I'm purposely keeping the frame rate low in order to make the jittering more apparent.

    As you can see in the video, by changing Time.DeltaTime to a constant value it solves the issue, but of course that can't be a solution.

    The whole script is in the image.

    Also, since I thought it might be related to the way I'm reading the rotation of the camera, I tried multiple approaches, but nothing seems to work.
    I'm not sure what I'm doing wrong :(
     

    Attached Files:

    Last edited: Apr 29, 2022
  9. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Send me the project
     
  10. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
  11. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Thanks. Had a look at it. Your setup is good. The jittering is noise from Unity 2021 editor. There is most noise when an inspector is visible, least noise when you play fullscreen. In a build, it's perfectly smooth. Don't worry about it. Non c'e niente, non preoccuparti :)
     
  12. Gyro_Zeppeli

    Gyro_Zeppeli

    Joined:
    Dec 27, 2017
    Posts:
    12
    Alright, I checked in build with different frame rates and everything seems to work. That's a big relief!!!!

    Grazie mille!