Search Unity

Triggers, collisions, and isKinematic

Discussion in 'Scripting' started by Bampf, Nov 7, 2005.

  1. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    I played with two boxes with various box collider and rigidbody settings, and determined the following rule:

    - to get an OnTriggerEnter event, the object in question must have a rigidbody, isTrigger = true, and isKinematic = false. It doesn't matter much what the other objects has, provided it has a collider. It doesn't need to have a rigidbody, doesn't need to be a trigger.

    The isKinematic setting was the "trick" that had been tripping me up, so this was good to know. In my particular scene, it made sense for various obstacles to be non-kinematic triggers so all was well.

    But now I want to detect when my game units (chess pawns, if you must know) collide with each other, not just with the obstacles. But I need them to be kinematic.

    I thought that maybe the kinematic constraint wasn't needed for OnCollisionEnter (i.e. non-triggers) but I still only get the event when kinematic is off.

    Suggestions for work-arounds? (And why is non-kinematic a collision requirement, anyway?)

    Thanks,
    Matt
     
  2. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203
    With version 1.2 triggers will work between kinematic rigidbodies.

    At the moment, the only workaround is making non-kinematic rigidbodies.
    Or using Physics.CollideSphere every frame or shooting rays.
     
  3. Bampf

    Bampf

    Joined:
    Oct 21, 2005
    Posts:
    369
    That's good information; thanks.

    Does the OnTrigger[Collision]Enter event happen BEFORE the physics system applies contact forces? If A hits B, and in OnCollisionEnter( ) I destroy B, will A still react to the collision? (I'm hoping no but I am guessing yes- I'm away from my Mac at the moment so I can't try it.)

    Or maybe I can have rigidBody.freezeRotation=true, and set velocity to (0,0,0) after the collision.

    If these approaches don't work out I'll use one of your suggestions (rays or spheres.) My pieces can easily predict which other pieces they are about to hit, so the number of intersection tests would be small.

    Thanks for the help!
    Matt
     
  4. robertseadog

    robertseadog

    Joined:
    Jul 23, 2005
    Posts:
    374
    you mean use a sphere collider as trigger? When you say every frame I guess you mean to use it in a Update function but I can't seem to find any documentation on this?
     
  5. Joachim_Ante

    Joachim_Ante

    Unity Technologies

    Joined:
    Mar 16, 2005
    Posts:
    5,203