- Home /
Why does my trigger-collider receive Enter but not Stay or Exit?
Why would a mesh collider call OnTriggerEnter but not OnTriggerStay or OnTriggerExit? My coworkers and I are all baffled; all of our guesses have been disproved.
The design for my project involves a turret with an area of effect described by a symmetrical triangle (mesh from our modelers), with the point at the turret and scaled along the turret's trajectory to also touch the cursor.
When the user moves the cursor (mouse or touch), the area of effect rotates to look at it and scales to span the gap between the turret and the cursor. While all of this is happening, I need to know when collisions with other stationary things start, continue, and stop.
For completeness, I should mention that the same modeler made both the triangle and another mesh that I position by the cursor. The other mesh reports collisions just fine, but the triangle only reports OnTriggerEnter.
If I put a BoxCollider on the triangle, it works fine.
The other model is positioned near the cursor by placing it at the same position as an empty GameObject childed to the triangle. Since it receives collisions fine and collisions are supposed to require motion, I tried making another triangle and positioning the original triangle according to an empty GameObject on my new triangle (whew!). It didn't help. (I would include another picture, but I'm at my limit.)
So... What can I do to convince my triangle to work?
Is your $$anonymous$$eshCollider's isConvex
property set to true? That may be the issue. It gets too complicated for physics to calculate collisions if there's a chance that meshes can be concave shapes. the isConvex
property constructs a new mesh from the mesh you gave that ensures its convex; sort of like putting shrink-wrap on something.
@jbarba Convex doesn't seem to change anything. However, I tried swapping which mesh does what and then I get this problem on the other mesh (a semi-circle) while the triangle works fine. Pending a way to get Unity to cooperate, I'm writing code to just call Stay and Exit myself according to Bounds.Intersects. The number of colliders I'm concerned with is sufficiently small that this isn't insane.
Are you moving things non-physically, e.g. by changing transform.rotation and transform.position directly?
Changing the position directly doesn't prevent any of the collision/trigger messages from firing. In fact I rely on that as a way to hack around the fact that destroying on object doesn't cause Exit to fire.
Good to know. $$anonymous$$y understanding was that moving by changing the transform was non-physical and instantaneous, thus it would break collision detection (which calculates along the path traveled). I'll have to take another look.
Answer by sparkzbarca · Mar 07, 2013 at 09:41 AM
you should read the documentation. http://docs.unity3d.com/Documentation/Components/class-MeshCollider.html
first off for 2 mesh colliders to colilde they both must be marked convex.
You also need to look at the very bottom of the page and line up what kind of collider the semi-circle is and what kind the triangle is (for example one of them MUST HAVE a rigidbody). In order for this to work.
Anyways your answer is all there in the documentation on mesh colliders.
In all of my tests, the other collider is a primitive (sphere within the game, box in my test case). $$anonymous$$y apologies for not mentioning that; I hadn't realized it was important.
Your answer
Follow this Question
Related Questions
Trigger script does not work. 1 Answer
Mesh Collider Does Not Working 1 Answer
OnParticleCollision equivalent as a trigger 0 Answers
30 Collisions with tags alone 1 Answer
Character Controller collision on Mesh Colliders Slopes Issue. 1 Answer