Search Unity

Remove Player Jitter

Discussion in '2D' started by BobberooniTooni, May 6, 2021.

  1. BobberooniTooni

    BobberooniTooni

    Joined:
    Apr 9, 2021
    Posts:
    46
    I have spent far too much time trying to get rid of the jittering my velocity-based movement has for my player to no avail, so here's hoping someone here is kind enough to lend me a hand.

    Here is a quick clip of the current status:


    Player move code bit:

    Code (CSharp):
    1.     void FixedUpdate()
    2.     {
    3.         //apply breaks
    4.         if (isBraking)
    5.         {
    6.             rgBody.velocity *= breakAmount;
    7.             return;
    8.         }
    9.  
    10.         //add our boost speed to our regular speed
    11.         movementSpeed = normalSpeed + boostSpeed;
    12.  
    13.         //combine the user inputs into vector2
    14.         //and normalize the values so diagonal isn't faster
    15.         input = new Vector2(inputX, inputY).normalized;
    16.  
    17.         //move our character in the input direction with the movement speed
    18.         //and maintain part of our previous velocity to avoid abrupt changes
    19.         //and to allow drifting when there is no input
    20.         rgBody.velocity =
    21.             rgBody.velocity * 0.96f + (input * movementSpeed) / 10f;
    22.     }
    -I know camera movement can be a part of the issue, but I know my camera script is fine, and for my tests I turn off the camera movement.

    -Rigidbody2D Interpolation on my character makes the jittering WAY worse. I have no idea why.

    -I have tried smoothing the velocity increase differently, no improved effect.

    -I need velocity based movement, but even with moveTowards or movePosition I had the same stutter.

    Let me know if you have any advice on a solution to this seemingly small problem, but a frustrating one nonetheless.

    o_O
     
  2. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    You're expecting frame-rate to be solid in the editor that's also redrawing all of the editor and doing all the background stuff? You'll always be sharing frame-time with the editor which is why you should test it in a build on a quiet device.

    The video looks perfectly fine to me which makes me suspect you're either looking at the screen response time issue or that the "jitters" are small and caused by the above.

    Yeah, that makes no sense.
     
  3. MelvMay

    MelvMay

    Unity Technologies

    Joined:
    May 24, 2013
    Posts:
    11,459
    Note that this'll be your issue but you are free to run the physics per-frame so you don't even need interpolation at that point.
     
  4. BobberooniTooni

    BobberooniTooni

    Joined:
    Apr 9, 2021
    Posts:
    46
    Even the build has a noticeable jitter. Right now my camera makes the player look smooth but surroundings have that little jitter.