- Home /
How can I limit collision force?
I need to limit a ball's bounce force when it hits other colliders.
I already limited rigidbody.velocity using Vector3.ClampMagnitude, but this does only decrease the bounce force speed at different values of hitting force. It does not give a limit to the ball's speed after hit which the ball should never exceed due to bounce force.
I need this because I have some kind of a pin pong game and I don't want the ball to exceed a specific speed limit because of the bounce force on hit. Because if it does so, physics gets weird.
So what I have in mind to solve this problem
function OnTriggerEnter (item:Collider) {
print("y");
if(item.gameObject.tag == "softpillow") {
rigidbody.velocity = Vector3.ClampMagnitude(rigidbody.velocity, maxSpeed);
//this does not limit the ball's speed on hit but only decreases it.
//I need to limit ball speed here.
}
}
How can I limit the collision force so that I can limit the speed at which the ball bounces off?
Have you setup your physic material for both your softpillow and your ball for the bounce you want? Have you played with the mass of the ball?
yes I did but that does not give an absolute limit. If you observe well, the ball's speed after collision is relevant to the force used when hitting. A higher force will result into sending the ball with a higher speed. Limiting the rigidbody's velocity or bounce from physics material will only decrease the speed, thus a much greater force will be required to go overspeed again. But I need to absolutely limit the speed, so the limit is never exceeded even if a huge force is applied when hitting.
Answer by Posly · Feb 21, 2013 at 07:20 PM
I'm not too experienced with rigidbodies but I think something like this would work: var speed : float;
var maxSpeed : float;
function Update ()
{
if(speed > maxSpeed) {
speed = maxSpeed;
}
}
I think that is the same as
rigidbody.velocity = Vector3.Clamp$$anonymous$$agnitude(rigidbody.velocity, maxSpeed);
but I'll give it a try.