Is there a way to switch a collider on and off?
I am doing all of my collisions with Physics.Linecast. I have two concentric spheres, and I wish to be able to switch each of them individually between “colliding” to “non-colliding”
Is there a way to switch a collider on and off?
I am doing all of my collisions with Physics.Linecast. I have two concentric spheres, and I wish to be able to switch each of them individually between “colliding” to “non-colliding”
Hmm, I can prevent an object from registering a collision with:
active = false;
However, it seems that this also prevents the object from reactivating itself, because all scripts on the object stop updating.
I suppose I could workaround by creating a “control” empty object to set it active or inactive.
Any other suggestions?
You can set the “isTrigger” property to true and you will have no collisions - only trigger events.
second option is to use “Physics.IgnoreCollisions” - look it up in the docs.
and a third option will be to change the scale and position of the collider to a "safe place”. by changing the bounds of the collider.
Colliders can’t be disabled/enabled, but they can be destroyed and re-added. Aside from Physics.IgnoreCollision, you could also use layer masks to selectively choose what is detected with the linecast.
–Eric
Thanks for the help, I love the fast feedback on this board!
I have gone for the “manager” GameObject technique, I have found that I can assign multiple mesh colliders to a manager and have it switch between them at will. I’m not sure what good that would be, but I am sure it will come in use somehow. It’s a cool solution which is looking for a cool problem!