When I apply the following function to RigidRoundHand_L or R I can switch collision for the hand tied to the object on or off.
void CollisionsSwitch(GameObject gameObject, bool flag)
{
Debug.Log("gameObject in CollisionsSwitch: " + gameObject);
Rigidbody[] rigidbodies = gameObject.GetComponentsInChildren<Rigidbody>();
foreach (Rigidbody body in rigidbodies)
{
body.detectCollisions = flag;
}
}
My problem is that when I move a hand onto and off the scene it may be registered with either RigidRoundHand_L or R. This is a problem because I need to selectively switch collision off for either only the left or right hand. So I want to do something like
if(RigidRoundHand_L.IsLeft)
{
do something
}
Of course this does not work because IsLeft is an attribute for Hand objects, not GameObjects like RigidRoundHand_L, so what can I do?
I read through the well documented Hand docs and found that I can do the following to get a hand and check its handedness:
// Get all the hand objects
Frame frame = leap_controller_.Frame(); // controller is a Controller object
if (frame.Hands.Count > 0)
{
List<Hand> hands = frame.Hands;
for(int i = 0; i < length(hands); i++)
{
Hand currentHand = hands[i];
if (currentHand.IsRight)
{
Debug.Log("Right!");
}
}
}
The above code works and as I watch the debug log I can see that as I move my right hand into and out of the scene the hand alternates between being registered to RigidRoundHand_L and R, but the above code always correctly identifies that it is my right hand.
That's all well and good but I cant find a way to switch off the collision of a hand object, so there is still a disconnect in that I cannot find a way to get the Hand object from a GameObject or the GameObject from a Hand object
Right now I'd love to be able to do something like this where getPhysicsModelGameObject is the missing magical function I cant find:
if(currentHand.IsRight)
{
rightHandPhysics = currentHand .getPhysicsModelGameObject();
> // Turn off collision
CollisionsSwitch(rightHandPhysics, false);
}
Maybe I'm missing something trivial? Maybe I'm asking for the the equivalent of this for the new Orion API? I cant find GetAllGraphicsHands() or GetAllPhysicsHands() in the Orion docs though.