- Home /
how do i correctly use a box collider
For my game, i want to have a fog of war. I want the enemy to be rendered only in the lighted area. So i expanded the box collider of my player(a little cube) and i've set up the OnTriggerEnter(hit:Collider) function on my enemy. The problem : unity do not detect anything when player and enemy touch. The OnTriggerEnter funtction is never called :( pls help
Ps: both player and enemy have rigide bodies and colliders
check out UnityGE$$anonymous$$S.com, beginner article, for a full discussion
@Fattie - just as an FYI I changed it's name to Common Gotchas (to try to be less pejorative) - the link is the same
@why .. gotchya ... i'm thinking would it be advisable to have a super easy URL for that page
like unitygems.com/gotchyas or the like ?
You can use http://unitygems.com/mistakes right now. I have to play with the PHP to change it, but I was thinking of doing that.
Answer by lil_billy · Oct 19, 2012 at 02:56 PM
ok so I dont know how you have it exactly set up however I can guess a certain number of pitfalls that you may have run in to.
-first trigger colliders only detect when the colliding object has both a SOLID collider and a rigidbody
-second in you if statement dont use "==" use other.gameObject.CompareTag ("object")
-third, never deactivate a gameobject (its almost like destroying it but it still takes up memory) instead de - enable target components that are relavant to your desired effect, in your case disable the mesh renders which you can than renable on trigger enter. DONT disable any colliders
-feel free to use as many colliders as you can, just remember there should be only one solid collider per any interactive gameObject and 99% of the time you dont want to mess with it.
Collisions between two colliders set to isTrigger = true are registered with OnTriggerEnter - if that's what you meant by SOLID, then your first statement isn't true. If you didn't mean that then I'm missing something.
not in my personal experience, i've noticed that occasionally it will ignore collisions between objects with both having only trigger colliders
Well that should be reported as a bug to Unity. I use this technique all the time.
Your answer
Follow this Question
Related Questions
how do i correctly use a box collider 0 Answers
Collision Checking 1 Answer
Trigger Spawning? 1 Answer
How to block collision between selected objects 0 Answers
OnTriggerEnter - Explosions that appear on the surface of hit object 1 Answer