- Home /
isKinematic rigidbody collisions
I want to detect collisions between two moving box colliders but have no need for any physics calculations to occur. I am currently moving them using their transform's in scripts attached to them. I set them both to have isKinematic=true rigidbodies and attached a box collider to each with isTrigger=true.
I also attached a script to each box:
void OnTriggerEnter(Collision collision)
{
Debug.LogError("HIT");
}
However I am not seeing any collisions, I have verified that the boxes collide at one point in the scene editor whilst debugging the game but no messages are logged. Is there something I am doing incorrectly?
Answer by AeonIxion · Nov 21, 2013 at 11:12 PM
Change the type of your parameter to Collider instead of Collision
Hmmm...yes, the parm type is wong, but that normally gives an error. Unless the script isn't a monobehavior?
Answer by jabez · Nov 21, 2013 at 11:14 PM
if you want to enable it when it hits add rigidbody.isKinematic = false; to your script other then that freeze the postion & rotation of the rigid body to avoid it moving around. from the wiki
if isKinematic is enabled, Forces, collisions or joints will not affect the rigidbody anymore. The rigidbody will be under full control of animation or script control by changing transform.position. Kinematic bodies also affect the motion of other rigidbodies through collisions or joints. Eg. can connect a kinematic rigidbody to a normal rigidbody with a joint and the rigidbody will be constrained with the motion of the kinematic body. Kinematic rigidbodies are also particularly useful for making characters which are normally driven by an animation, but on certain events can be quickly turned into a ragdoll by setting isKinematic to false.
Answer by Owen-Reynolds · Nov 21, 2013 at 11:18 PM
Intended behavior. From the docs (http://docs.unity3d.com/Documentation/ScriptReference/MonoBehaviour.OnTriggerEnter.html):
"Note that collision events are only sent if one of the colliders also has a non-kinematic rigidbody attached."
I assume this is because the physics system sends the messages, which saves time by not checking things that it will never move. Not to say there aren't workarounds. Wonder if checking all the constraints and leaving isKen off would work (google has more suggestions.)
Your answer
Follow this Question
Related Questions
OnTriggerEnter mesh collider problem 1 Answer
Rigidbody Trigger 1 Answer
Physics Possibilities?: Angles, Penetration, Exceptions 4 Answers
how to turn a particle emitter on & off with a rigidbody trigger? 2 Answers
Is it possible to block a collider with a trigger from hitting and object behind it? 1 Answer