- Home /
Collision question
Hi, I'm a little confused about rigidbody collision. I have a static mesh collider, with OnTrigger set to true. When a rigidbody collides with it, the rigidbody passes through it without collision. However, Set OnTrigger to false and the collision is detected. I assumed the collision would still work, but it was the message sent (OnTrigger vs OnCollision) that differed.
The static mesh colliders are a series of static platforms, however there are physics objects in the game that I want to collide with these static mesh colliders - but I don't want give all of them rigidbodies...can anyone suggest a solution? BTW have been looking at this before someone points it out :-)
Thanks in advance for any tips.
Answer by Bluestrike · Jan 08, 2013 at 06:00 PM
In Short: Oncollision uses contact detection and gives you info on the contact point. OnTrigger is used for invisible triggers like a trigger activating a trapdoor of special event in a level.
When you have a mesh and generated a collider for it you can attach a script to it that uses the OnCollosionEnter() OnCollisionExit and OnCollisionStay() functions. And youre mesh is solid and physics wil interact with it.
When you mark a collider as is trigger, the mesh is no longer solid but a trigger volume. You can use OnTriggerEnter() OnTriggerExit() and OnTriggerStay() functions. Usually trigger volumes to not have a renderer as triggers are generally invisible. Water could be an exception.
A rigidbody should only be given to physics objects like interactive crates. For static objects you just need a collider and rigidbody's will interact with it. For example: in a ball physics game, the ball would need a collider and rigidbody while other geometry like doors and the floor just need a collider.
Ok so when I flag an object with OnTrigger, I have to handle any 'collision' or behaviour in code with OnTriggerEnter etc. Alternatively, not having OnTrigger (as you say) means that the collision is handled automatically, but I can also detect this with OnCollisionEnter etc
Yes with a trigger you get also different information back, a Trigger gives you the collder info wfrom the colliding rigidbody.
While the Collision gives you collision info like the point in space where the hot occured.
This may help you out: http://docs.unity3d.com/Documentation/Components/class-BoxCollider.html