- Home /
Rigidbody2D.addforce giving jerky movevent
I'm attempting to apply a force to the player whilst it is below the maximum speed, then stop applying the force once the max speed is reached, until the player stops holding the relevant button.
Unfortunately, this is causing very jerky behaviour and some framerate drops. The following is being called by FixedUpdate():
int dir = (int) Input.GetAxisRaw("Strafe");
if(Mathf.Abs(_r.velocity.x) < _vMax && dir != 0)
{
_r.AddForce(new Vector2(dir * acceleration, 0), ForceMode2D.Force);
}
The acceleration is a constant defined in the code, and _r is the player's Rigidbody2D component.
Your answer
Follow this Question
Related Questions
How to use the new Physics2D.OverlapCapsule & CapsuleCast 0 Answers
Is calling OnCollisionEnter2D on allot of GameObjects bad for performance? 2 Answers
Problem with 2D collision detection (Wide object falls through a thin hole) 1 Answer
Hingejoints 2D going crazy!! Can it be a bug? 0 Answers
Physics2D.IgnoreCollision not working! 0 Answers