- Home /
Physics.IgnoreLayerCollision - Help
Hello,
I have a cube on my game with a box collider, I also have an enemy with a capsule collider - I would like my enemy to walk through the box by avoiding any collisions.
I have given my cube a layer called "EnemyIgnore" (layer 8).
In my Enemy AI script, I have put in the Awake Function:
Physics.IgnoreLayerCollision(8,8, true);
But this doesn't seem to work, what am I doing wrong?
Also, I don't want to use any triggers ... I just want this to be a one off 'no collision' detection, thus causing my enemy to walk through the cube, and vise verser.
Thanks
This isn't an answer, but thank goodness someone worded this script with just the 8,8,true, as numerical values or I would never have gotten past the "layer doesnt exist" issue. I couldn't for the life of me figure out how to make it read the layers when I typed in Layer8,Layer9. Now I feel dumb.
Answer by Owen-Reynolds · Aug 31, 2011 at 02:04 PM
What layer is your enemy on? So far, you've said that things on EnemyIgnore won't hit themselves (other things on layer 8.)
Seems like you need an Enemy layer 9, and IgnoreCollide(8,9)
Also, you can go to Edit->physics and check the matrix there, if you aren't totally confident the code line is getting the job done.
Answer by Molix · Aug 31, 2011 at 02:03 PM
You have set it so all objects in the EnemyIgnore layer will ignore collisions with all other objects in the EnemyIgnore layer, but from your description that does not seem to be what you want. For one, your enemy is probably in a different layer (e.g. an Enemy layer), and for another, it is not really a one-off in that all objects on those layers will be affected.
So either check the layer of your enemy, or, if it is really just a 'one off', then you can just use Physics.IgnoreCollision to specify the two object's colliders specifically.
Physics.IgnoeCollisions has the annoying problem that when objects are disabled the setting is lost. Physics layer-based collision is way easier to manage if you have, for example, distant objects being disabled for performance reasons.
Your answer
Follow this Question
Related Questions
Enable / Disable Layer Collision Matrix thru Script 1 Answer
Physics Collision Layer Programmatically. 0 Answers
revert Physics.IgnoreCollision 2 Answers
How do you enable the layer based collision matrix? 1 Answer
Collision stuck issue 0 Answers