Search Unity

Question a few issues with jittery movement after adding an input-controlled systems to Body

Discussion in 'Cinemachine' started by k_dunlop, Oct 13, 2021.

  1. k_dunlop

    k_dunlop

    Joined:
    May 10, 2019
    Posts:
    16
    I have this code on my main character, kept in Fixed Update. Works a charm whenever the screen is still but as soon as I start to add something with inputs like the orbital transposer the screen starts rapidly jittering, and I can't seem to track down why.
    Could it be related to the Cinemachine Input Provider inputManager? I've set it Mouse/MouseLook/Delta/Pass Through/Vector 2

    Cinebrain update method is set to Smart. Blend Update is Late


    Code (CSharp):
    1.    private void RotateThisObject(Ray ray)
    2.     {
    3.         RaycastHit hit;
    4.         if (Physics.Raycast(ray, out hit, 100f, layerMask))
    5.         {
    6.             if (Vector3.Distance(this.transform.position, hit.point) > 0.5f)
    7.             {
    8.                 Vector3 eulerRotation = Quaternion.LookRotation(hit.point - this.transform.position).eulerAngles;
    9.                 eulerRotation.x = 0;
    10.                 eulerRotation.z = 0;
    11.                 transform.rotation = Quaternion.Euler(eulerRotation);
    12.             }
    13.         }
    14.     }
    15.  
    16.     private void ShootRayCast()
    17.     {//Creates a Ray from the camera(which moves according to the vCam location) in the direction of the position of the mouse
    18.         //The ray then hits a collider I put on the Mall game object and then put that object(only that object even though it's the parent)
    19.         // on the 'Ground_Rotation' layer so that the rotation is smoother and doesn't jump on every object.
    20.  
    21.         Ray ray = Camera.main.ScreenPointToRay(mouseWorldVector);
    22.         Debug.DrawRay(ray.origin, ray.direction * 100f, Color.red, 1f);
    23.         RotateThisObject(ray);
    24.     }

    I have noticed that this jitter only occurs whenever I move the mouse over the object Ground_Rotation, which is the a big collision box used to raycast towards and move the player in the direction of the mouse. layerMask = LayerMask.GetMask("Ground_Rotation");


    Thanks!
     
    Last edited: Oct 13, 2021
  2. Gregoryl

    Gregoryl

    Unity Technologies

    Joined:
    Dec 22, 2016
    Posts:
    7,711
    Jittery movement is often caused by inconsistent motion of the tracked target: sometimes the transform is being altered in FixedUpdate(), and sometimes in Update(). The solution is to move the target on one clock only: either consistently in FixedUpdate(), or consistently in Update(). Don't mix them.
     
  3. k_dunlop

    k_dunlop

    Joined:
    May 10, 2019
    Posts:
    16
    Thanks, sorry for the late reply. I didn't get any notifications