I’ve laid my wave paths out in such a way that they intersect at times and certain enemy ships occasionally collide with each other. I’ve attached appropriate layers to my enemies to mark them as such, and disabled the “enemy” layer colliding with other “Enemy” layer type entities in the project settings, but the enemy ships still blow each other up on contact. Any idea how to fix this?
Hi Fenmox,
That’s odd. Given all enemies are on the Enemy layer and given you disabled the interaction between game objects on the Enemy layer, the enemies should not be able to collide with enemies anymore.
Are you sure that the enemies shoot each other? How did you verify that? With a Debug.Log in the OnCollisionEnter2D method where you logged the name of the other game object into your console? If not, do that please. Maybe there is a collider attached to another game object colliding with the enemy.
The enemy lasers must be on the Enemy layer too. Or on a layer that does not interact with the Enemy layer.
Hi Nina, I haven’t added any bullets or lasers yet. This is simply the enemy ships colliding with each other.
Did you configure the layers in Physics2D or Physics? Make sure it’s Physics2D
My bad. I noticed that after I wrote my previous answer and edited it accordingly but I obviously missed a ‘shoot’. It should have said ‘collide with each other’. The questions remain the same because it does not matter if the enemies are getting destroyed by other enemies or by lasers because, in the end, it’s a collision. At least, that’s what you think is happening at runtime. Now you have to verify that to figure out more about the problem. That’s how debugging works.
Before you do that, check what bixarrio suggested. The settings look basically the same, so it is easy to inadvertendly click ‘Physics’ instead of ‘Physics2D’.
Yep, that was it. My bad. I updated to a newer version of Unity for this project, in the 2021 version they were both in the same tab.
This topic was automatically closed 24 hours after the last reply. New replies are no longer allowed.