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. Dismiss Notice

The scene jitter while controling camera's position and rotation by scripts

Discussion in 'Cinemachine' started by LmyJD, Nov 18, 2021.

  1. LmyJD

    LmyJD

    Joined:
    Nov 18, 2021
    Posts:
    6
    “If you want to control the Camera's position directly by script after it has a CM Brain, create a passive Virtual Camera (i.e. a CinemachineVirtualCamera with Do Noting in both Aim and Body), make it high priority to make it drive the main camera, then have your script control its position, rotation, and FOV.”By Gregoryl.
    I set the "Body" as "Do Nothing" and set the "Aim" as "Do Nothing",then control the camera's position and rotation directly by scripts in Update.But the scene jitter.How can i solve this ?
     
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Scene jitter is often caused by uneven motion, either of the camera or of the objects in the scene or both. You need to look at your motion scripts for the cause. Often it happens that people mix Update() and FixedUpdate(). Try moving everything into Update(). If you then have jittering RigidBodies in your scene, turn on interpolation for them.
     
  3. LmyJD

    LmyJD

    Joined:
    Nov 18, 2021
    Posts:
    6
    I control a GameObject(CarBody) position by Cinemachine Dolly Cart and the Update Method is "Update". The CinemachineBrain's Update Method is "Late Update" and Blend Update Method is also "Late Update".My motion scripts is bind on the Do Nothing VCam.There is still Scene jitter.How can I solve this?

    I control a gameObject(CarBody) by Cinemachine Dolly Cart.Its Update Method is "Update". The CinemachineBrain's Update Method is "Late Update" and its Blend Update Method is "Late Update".I bind the motion scripts on a Do Nothing VCam and set it as live Cam.There is still Scene jitter.How can i solve this?
    Follow is the motion script.
    Code (CSharp):
    1. void LateUpdate()
    2.     {
    3.         this.transform.rotation = originalCam.transform.rotation;
    4.         this.transform.position = carBody.transform.position;
    5.         Vector3 originalRelativePos = this.transform.InverseTransformPoint(originalCam.transform.position);
    6.         Vector3 presentRelativePos = new Vector3(-originalRelativePos.x, originalRelativePos.y, originalRelativePos.z);
    7.         Vector3 presentAbsolutePos = this.transform.TransformPoint(presentRelativePos);
    8.         this.transform.position = presentAbsolutePos;
    9.     }
     
  4. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    I don't understand what that code is trying to do. What is "originalCam"?
    Can you describe in words how you want the camera to behave, relative to the car?
    Can you show a video of the jitter?
     
  5. LmyJD

    LmyJD

    Joined:
    Nov 18, 2021
    Posts:
    6
    I want to get the effect like video1.When the car turn left, we can see the left side of the car and the car is to the right of the center of the screen.
    originalCam is a VCam that Transposers to the car and composers to the car.
    But the result of the originalCam is when car turn left,we can see the left side of the car and the car is to the left of the center of the screen.
    So I calculate a new transform by originalCam and car and then assign the transform to a Do Nothing VCam.I get the effect I want .But there is Scene Jitter. like Video 2.
     

    Attached Files:

  6. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    I understand, thank you. The strategy of tracking one vcam with another is not good, because the order of evaluation is wrong. Your code is using the originalCam's position from the previous frame.

    A better solution would be to remove the DoNothing vcam and set up the car vcam's composer to look ahead of where the car is, and then you would naturally get the effect when the car turns. Try setting this binding mode in the transposer, and adding some lookahead to the composer (experiment with the amount until you get the effect you want).

    upload_2021-11-18_8-32-18.png
     
  7. LmyJD

    LmyJD

    Joined:
    Nov 18, 2021
    Posts:
    6
    It works! Thank you.While I find that sometime when the car go forward,the cam also towards the left or right side.I try to set the "Lock to target with World Up"Binding Mode in the transposer and set the Yaw Damping and think it will be more meet my needs.In addition.If I want to tracking one vcam with another for other cases ,how can I correct the order of the evaluation?
     
  8. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,233
    Unfortunately, no. You can't track vcams in a reliable order. Instead, use intermediate invisible targets that you position according to your game objects (not the vcams) and have your vcams track those.
     
  9. LmyJD

    LmyJD

    Joined:
    Nov 18, 2021
    Posts:
    6
    I see. Thank you very much!