Search code examples
unity-game-engine2dphysicsvelocitysmoothing

Unity - How to Smooth Out Constant Velocity on Rigidbody2D


I am setting constant velocity for my character movement in my 2D game. However since using the method my character seems to be shaking a little. Is there a way to fix this and smooth the movement out?

Here is I set the velocity in the Update function:

constantVelocity = new Vector3 (playerInputX * speed, playerInputY * speed, 0);

I then apply this velocity to the the Rigidbody2D component in the FixedUpdate function.


Solution

  • It turns out that my problem had nothing to do with the object I was moving but the camera that was following it. The camera was trying to Lerp towards the object in Update. I changed this to FixedUpdate and it now works perfectly.

    Thanks for the help anyway,

    Tommy