I'm making a unity game, I have enemies that have to go through all objects except themselves. That is, I set a "Is Trigger = true" for them, and they easily fly through all the objects, but they also collect in a heap over time and it’s not clear how many enemies fly after me.
I know about such a method as "Physics2D.IgnoreCollision()", but I can not find a normal explanation of how it works.
In general, you need to teach objects to ignore the same as them.
CodePudding user response:
Use Unity's layers and collision matrix.
Assign the enemies to a layer named Enemy
To do this, select the Enemy GameObject (or prefab) and click Layer > Add Layer
Type Enemy
into User Layer 8 or any blank slot
Go back to the Enemy GameObject/prefab, click Layer > Enemy
Change the collision matrix to ignore collisions between enemies:
Go to Edit>Project Settings>Physics and uncheck the Enemy > Enemy checkbox in your collision matrix (see image for example collision matrix)