Physics question

Hi all,

I was wondering if anyone has any insight into how I would make physics be “conditional”. Essentially, I want collisions to not be computed for objects that have some flag the same, but be computed for everything else.

I’ve tried checking that in the OnCollisionEnter and using Physics.IgnoreCollision, but it seems that the collision is calculated before it calls the OnCollisionEnter (or at least, to the point where it’s too late to do anything about it).

Any help on this issue would be very helpful!

Thanks,
-T

Manually make the flagged object ignore each other when you instantiate them.
I had the same problem while doing a crate-dropping system (I want the player to collide with the crate to pick them up, but the crates shouldn’t collide with each other).
Basically you need to make a list of all your objects, and iterate Physics.IgnoreCollision. If your objects are tagged, use GameObject.FindWithTag to get that list.

Great thanks! The only problem is that the flag that I have (and when I say flag, I really mean a variable in a script) can change depending on game play. Is there a way, then, to get every object that has this specific script attached to it?

Thanks,
-T

Object.FindObjectsOfType

Sweet. Thanks guys!