Hello!
I have now been sending objects into space by hitting them with other objects which got me wondering if there is a way to set a universal value of max speed allowed for all objects?
Hello!
I have now been sending objects into space by hitting them with other objects which got me wondering if there is a way to set a universal value of max speed allowed for all objects?
The physics engine provides a limit for angular velocity (Physics.maxAngularVelocity), but not for linear velocity. If you want to limit the linear velocity of a rigidbody, attach a small script like this to it:
function FixedUpdate(){
// clamp rigidbody velocity to 20 m/s:
rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, 20);
}
The worst problem with high linear velocities is the “tunnel effect”: the rigidbody may apparently “pass through” other colliders without colliding with them. This happens because the physics engine works in discrete steps: a fast rigidbody may be before a collider in one step and after it in the next one, completely ignoring the collision. Unity provides continuous collision detection as an alternative, but it’s too expensive and limited to sphere, capsule and box colliders, thus it’s better to avoid using it.