How to make kinematic rigidbody react to some collisions

I have a number of objects with rigidbodies on my scene. Some of them are kinematic to make them stable. However, if a kinematic object is hit by a special type of object, it needs to react as if it was not kinematic, i.e., it needs to become non-kinematic, and react to the same collision that makes it non-kinematic.

If I use

OnCollisionEnter(Collision collision)
{
    rigidbody.isKinematic = false;
}

the object becomes non-kinematic, but fails to react to that collision. My guess is that the collision has already begun, changing “isKinematic” in “OnCollisionEnter” is too late.

Which means, I somehow need to know the collision right before it really happens.

Any suggestions?

Rather then making it kinematic, you can give it its own layer and use the Physics settings to control what other layers it interacts with.

Note that this will ALSO prevent it from applying forces to anything it is set not to interact with.

If thats not what yo want then yo hare likely into scripting specific application of forces from specific objects.

you could use your code then add a force to the object yourself to get it moving.
(series of events.)

  1. gets hit
  2. turns itself non kinematic
  3. gives itself a large push in the right direction.
  4. everything else that happens.

I think You can make another Collider that will be trigger and set it to be bigger than actual collider (the bigger velocities, the bigger offet You will need to use) and then in OnTriggerEnter set rigidbody to non-kinematic. This should work.

Make the object not use gravity, and when hit make it use gravity. Th rigidbody should NOT be kinematic.

function OnCollisionEnter(collision : Collision) {
rigidbody.isKinematic = false;
}

function OnCollisionEnter(collision : Collision) {
rigidbody.isKinematic = false;
}