- Home /
Collision detection only half working.
I'm having a little bit of trouble with my collision detection. I have a player cylinder which rotates around a centre point using 2 keys. From that centre point, cylinders are instantiated and scaled up, so heading towards the player. I need to get a collision detection working to detect if the two objects have entered and exited one another however I'm having some trouble. If I set my player as a trigger and use onenter/onexit it only works half the time and the player has to be moving at the time of the collision for it to be detected, if it's stationary no collision is detected, also onexit is never detected. The player has rigid body, sphere collider which is a trigger and is detecting the collisions. The other objects have mesh colliders. Any ideas?
Answer by Raggers · Sep 23, 2014 at 03:09 PM
Don't know if this fixes your problem: Try adding a ridgidbody to your cylinders.
Some tips on physics:
Boxcolliders (or meshcolliders) are meant to be static objects. If they are not moving they are put to sleep to save CPU resources and only a other moving object - like your player - will interact with them but only if it is moving, if not your players collider is put to sleep too.
Ridgidbodies are the dynamic version of a collider. Moving a collider uses more resources then moving a Ridgidbody.
Setting the position of a ridgidbody is not seen as moving it, to move a Ridgidbody use the MovePosition() function.
And if you Ridgidbody is kinetic you need to use the FixedUpdate() to interact with it. This is because the physics layer is not in sync with your Update() function. Where as FixedUpdate() will be called before every physics update.
To sum it all up: Boxcolliders are static, Ridgidbodies are dynamic, always use FixedUpdate() for physics interaction and if two objects are not moving they can never hit so the physics layer ignores them.
(Please correct me if I am wrong, still learning the ins-and-outs of unity)
Your answer
Follow this Question
Related Questions
how to make an Explosive rigidbody trigger by another collision box 0 Answers
OnCollisionEnter not called on Unity4.3 for 2D. 1 Answer
rigidbody collision and forces 0 Answers
Why is this rigidbody not activating the trigger? 0 Answers
Turning an object into a RigidBody and applying a force on it... 2 Answers