Ignore Collision

I have a weapon that shoots a spread of rockets. I want the rockets to collide with walls and enemies, but not with each other. Right now they are all rigidbodies with box colliders on them. I have them set to destroy on collision with tags "Enemy" and "Wall". But they still collide with each other and bounce all over the place. Is there a way to have them ignore collision with each other?

I tried using

if(hit.collider.GameObject.CompareTag("Bullet"))
     Physics.IgnoreCollision(collider, hit.collider)

But that nothing changed at all. Any ideas?

It is actually quite simple to do :

  1. Create a new layer called “Rockets”
  2. Set the Layer of the rocket prefab to “Rockets”.
  3. Go to Edit > Project Settings > Physics
  4. Ensure that the checkbox in the Layer Collision Matrix is unchecked for Rocket-Rocket collision.
  5. That will disable all collision between rockets and othe rockets.
  6. Party on.

You can't use IgnoreCollision after objects have already collided, because the collision has already occurred, and therefore can't be ignored...it can't go back in time to the previous frame and be applied retroactively. The idea is to use IgnoreCollision beforehand, such as when the objects are instantiated.

Or you can just use collision layers and not bother with IgnoreCollision at all.

Another way you could do it, would be not make the objects have physics until right before the collision, so u could ray cast out and then add a collider or rigid body component, or what have you on collision with that ray, might be more confusing, but I think it would work... I think

Wonderful!!! Thanks, don’t even have to use code for this!