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

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.

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.