Ah, I see.
So, there was a collision between enemy ships, and your solution (at the moment), is to simply move the waypoints further away to prevent the collision - is that right?
Assuming so, and as mentioned above I’ve not been through the update content yet so it may be mentioned in a lecture you’ve not got to, but you could just ignore the collisions where they are not relevant.
There are a couple of ways you could achieve this, one would be via code, in your OnTriggerEnter2D
method, use an if
statement to determine the type of thing that has made the collision and only do something if it’s something you care about. For example;
private void OnTriggerEnter2D(Collider2D other)
{
Projectile missile = other.gameObject.GetComponent<Projectile>();
if (missile)
{
// ...
}
}
The above is a snippet from the original course content. It creates a local variable missile
of type Projectile and then calls GetComponent
on the GameObject other which was involved in the collision.
Next, a test is made to see if missile
is anything but null
, if it is, then it was a projectile that hit the ship and we can do whatever would be appropriate. If it wasn’t, nothing happens.
I appreciate that these types may not be used in the updated version of the course, Projectile for example, but hopefully the above outlines a way that you can be discerning when it comes to collisions and base a course of action upon it.
Another approach would be to use Layer based collisions. You would create layers for perhaps the enemies, and the player, then using the Collision Matrix you can simply tick/untick the collisions that you are interested in. If you were to untick the enemy/enemy option for example, you would not receive any messages when a GameObject in the enemy layer collided with another GameObject in the enemy layer - as such, your enemies wouldn’t destroy each other on contact. You could also add their lasers/missiles to the same layer which would then prevent them from shooting themselves also.
As mentioned above, this may already be covered in the updated content, so maybe check the names of the lectures before jumping ahead too far in case it’s something you’ll cover in the next lecture anyway
Hope this helps
See also;