Search Unity

Rigidbody movement and shuttering on camera for character

Discussion in 'Scripting' started by Benmaster, Jul 25, 2020.

  1. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    I have issues to sync the character movement using physics (to allow interoperate with any physic object in the scene in real way) and the camera follow the character.
    For the camera im using LateUpdate and Lerp to follow the character smoothly.

    And for the character movement im using this:

    Code (CSharp):
    1.             RigidBody body = transform.GetComponent<RigidBody>();
    2.             float yVel = body.velocity.y; // Store Y force to dont override gravity
    3.  
    4.             Vector3 movement = new Vector3(moveHorizontal, 0f, moveVertical);
    5.             Vector3 newVel = movement * speed;
    6.  
    7.             newVel.y += gravityReduction;
    8.             body.MovePosition(transform.position + (newVel * Time.fixedDeltaTime));
    But I notice a micro shutter in the character itself when the camera moves following with some delay, and is more notizable if you reach many FPS. I try with V-sync on/off and also with this methods for the character movement:


    LateUpdate + Time.fixedDeltaTime = Inconstent movement, more FPS -> faster movement
    FIxedUpdate + Whatever = Micro Shutter on character
    Update + Time.deltaTime = Inconsistent movement to

    When I select the character element in the editor the movement speed changes (because the FPS in the editor is lower) also if the FPS jump, you notice how the character change the movement speed.

    Is there a way to move physic object with fixed movement independent of the FPS and get no shuttering?
     
  2. PraetorBlue

    PraetorBlue

    Joined:
    Dec 13, 2012
    Posts:
    7,910
    Is interpolation enabled on your Rigidbody?
     
  3. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    Yes, I try Interpolate and Extrapolate and the shuttering continues.
     
  4. Benmaster

    Benmaster

    Joined:
    Aug 11, 2016
    Posts:
    39
    I think the issue is related between move the character with FixedUpdate and the camera with Update/LateUpdate, and unity show some kind of.. "frame descompensation" but im not sure how i can evade it.