Hi,
I’m trying to get two or more instantiated objects of the same type to ignore collisions with each other, but not with other objects. I’ve tried Physics.IgnoreCollision, but I get the message “The two shape references must not reference the same shape.”
I used Physics.IgnoreCollision and it worked just fine. Get all the objects you want to test, loop through them and if object != the object that’s ignoring the collision AND it’s tag/label == “something”, let them ignore the collision.
Hmmm… Maybe I didn’t explain well enough. So what I have are basically a lot of balls flying through the air. I don’t want the balls to bounce off each other, but I do want them to be able to hit other things. I tried:
Ball is the GameObject that I assigned the prefab earlier. That didn’t work. Is there a way I can make it so that these balls, which are just instantiated versions of the same prefab, pass through each other, but not through other objects.
Now you won’t ever set an ignore collision to itself.
Although, you will likely need to store a List of these balls to iterate through to disable collisions;
i.e.
balls is a List of all your Ball GameObjects.
for(int i = 0; i < balls.Count; i++)
{
for(int j = 0; j < i; j++)
{
Physics.IgnoreCollision(balls*, balls[j]);* } } This is setup to only be called once, if you want to add balls at random times, you will just want to call ignore collision between the new one and all existing ones each time.