Search code examples
unity-game-enginecollision-detectioncollisiongame-physics

Unity3D, cube object not colliding


I'm having some problems with collision in Unity3D. It seems that collision is not working with game objects when I set their colliders as a trigger. Right now, I'm trying to make an inventory system so I've set obtainable items to have a collider as a trigger. When I walk into an object with the trigger on, the player simply passes through the object, and giving the object a rigidbody causes it to fall through the ground. When I turn off the trigger, the object acts as it should, and the player collides with it.


Solution

  • When you set a collider to act as a trigger, it no longer works as something that you 'collide' physically with. Instead, it allows another collider to enter its space and then it sends off a different type of message back to unity.

    If you want it to be that they bump into the object and it physically moves, don't make it a trigger. If you want them to be able to sort of 'enter its space', make it a trigger.

    Then, if you use it as a trigger, you need to use the OnTriggerEnter function to catch that collision.

    If you don't use it as a trigger, you need to use the OnCollisionEnter function.

    You can read more about colliders and collisions here.