How to ignore collisions on the same layer?
I want to use Physics.IgnoreCollision to avoid bullets hitting themselves. The bullets are spawned on layer 8. Why is this not working?
// bulletscript.cs gameObject.layer = 8;
// maingamescript.cs Physics.IgnoreCollision(8,8);
There may also be other objects on layer 8 that should also be ignored. (for example, the player ship).
Answer by EDevJogos · Aug 12, 2016 at 01:14 PM
You tagged your question as 2D Game, so i belive you should be using Physics2D.IgnoreLayerCollision();
Also note that it has to be IgnoreLayerCollision and not IgnoreCollision. Your code above shouldn't even compile.
I don't know much about the Project, but can't you use the Edit -> Project Settings -> Physics2D and uncheck the layers you don't want to collide ?
Yes, thanks, simply unchecking the layers in project settings worked! I also did not realise I had to call Physics2D ins$$anonymous$$d of Physics.