- Home /
How to limit my player speed (2D)?
My player is always bouncing but it bounces higher and higher. I want to limit the speed so my player won't be so fast. I'm using rigidbody.AddForce for the bounce.
Answer by benberazz · Oct 02, 2020 at 05:03 PM
Solved with this codes:
//Limit Speed
float maxSpeed = 10f;
if (rb.velocity.magnitude > maxSpeed)
{
rb.velocity = Vector3.ClampMagnitude(rb.velocity, maxSpeed);
}
//if you want to check.
void OnGUI()
{
GUI.Label(new Rect(20, 20, 200, 200), "rigidbody velocity: " + rb.velocity);
}
Answer by raaiiny_ · Oct 02, 2020 at 11:47 PM
Uhm.. if it keeps bouncing higher and higher and you already use AddForce to add the bounce force to the player per script, I think there's a material on that block with bounciness over 0 on it. Maybe you should reduce that to 0.
Your answer
Follow this Question
Related Questions
AddForce for spaceship acceleration, but with max speed 2 Answers
Keep Hinge Joint 2D swing speed? 1 Answer
Issues with 2d movement 2 Answers
How to make two objects collide without bouncing 2D 0 Answers
Trail Renderer - limit trail lenght? 0 Answers