Making a rigidbody stick to its position

When a collision with a collider happens, it's possible to detect velocity magnitude and trigger an event.

function OnCollisionEnter(collision : Collision) {  
    if (collision.relativeVelocity.magnitude > 2){
    	...
    }
}

How can I tell the attached rigidbody not to move when the magnitude is below that value?

Rigidbodies are controlled by physics (unless they have the isKinematic flag). This means that the physics system will decide whether the Rigidbody will move or not.

If you want to have control yourself over when it moves or doesn't move, you have a few choices.

  • You can make the Rigidbody kinematic, and only turn isKinematic off when you want it to move. Since it will probably be kinematic in the moment of the collision, you may need to apply a force to the Rigidbody yourself to make it move.

  • You can have the Rigidbody be physics controlled all the time, but overwrite its position and velocity when it has moved and you didn't want it to. Just store variables with the position and velocity before the collision, and if the collision impact was not big enough, set the position and velocity after the collision to the stored values.

There may be other ways to do it, but those are the ones I could think of off the top of my head.

I guess you could also try manually setting the rigidbody velocity if the impact isn't strong enough, which at least works better in theory than manually setting position.

Just my two cents

I'm not sure this will work, but you can try calling rigidbody.Sleep().

Alternatively, if you're just trying to control the level of bounciness, you can tweak the bounciness value in the physics materials.

You could have a placeholder Trigger (Box Collider) which upon Collision would or would not initiate a Prefab object in it's place (perhaps the trigger Collider would be larger than your Prefab Object) depending on the magnitude of the collision.?? That might work.