Reputation: 104
I want to move an object with AddForce but I don't want its speed to increase dramatically, without a limit, but to move with a speed limit set by a float value.
Upvotes: 1
Views: 3732
Reputation: 7660
You can use clamp to restrict your value(s);
https://docs.unity3d.com/ScriptReference/Mathf.Clamp.html
Upvotes: 0
Reputation: 526
You could probably use Vector3.ClampMagnitude:
rigidbody.AddForce(...);
float maxSpeed = 10;
rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed);
And don't forget to play with the force inside FixedUpdate()
not in Update()
Upvotes: 4