- Home /
Getting physics ignorance layers from script
I'm putting together an extension script to do more robust physics at high speed (hope to make it available if it works - should provide something more robust than Don'tFallThroughThings). I'm trying to make it easy for anyone to use (but also expose more advanced tools for those who need it).
Briefly: it's based on SphereCasts (just those for now - extending out based on collider type should be fairly easy). Sphere casts have a layer inclusion option.
I wanted to make sure that in its simplest form, it'd use the same layer as the rigidbody it's being applied to and then establish what layers it should ignore based on the Physics Manager Matrix (so that ignores all layers that it's been set up to ignore). At the moment I have to declare this manually.
Is there any way to pass a Layer number into Physics, and have a layer mask return which tells you which layers are ignored/noticed?
Answer by roamcel · Oct 27, 2011 at 11:28 AM
I believe there's only one way to do this, which is through the http://unity3d.com/support/documentation/ScriptReference/Physics.GetIgnoreLayerCollision.html function.
You basically scan the layer array, and call the layer collision getter with your reference layer as a source. Then you can decide how to manage that, for example by populating a custom array or matrix (there seems to lack a specific such object in the physics panel to access).
Ahh, so there is a way, albeit brute force. Thanks!
As it turns out, I found a work around using rigidbody.SweepTest - this obviously ignores itself when doing the sweep, while Physics.SphereCast needs to be told which layers to include.
Your answer
Follow this Question
Related Questions
How to achieve this basic physics effect? Detect when to change layers 2 Answers
How do I use layermasks? 9 Answers
Colliders attached to objects on separate layers are colliding? 1 Answer
Compute inertia tensor based only on colliders in same layer as parent? 0 Answers
Enable / Disable Layer Collision Matrix thru Script 1 Answer