Hi @Joe_Ward,
Following your previous advice I was able to get the hands to do what I wanted them to (You can see in the image below). However, I am having trouble moving the palm and forearm RigidBody objects to align with the newly transposed hands. I have tried to read the Graphics hand positions and to align them, but there have been several errors. I have tried this many ways but basically here's what I've tried in a nutshell.
namespace Leap.Unity
{
/** A physics model for our rigid hand made out of various Unity Collider. */
public class RigidHand : SkeletalHand
{
public override ModelType HandModelType
{
get
{
return ModelType.Physics;
}
}
public float filtering = 0.5f;
public override bool SupportsEditorPersistence()
{
return true;
}
public override void InitHand()
{
base.InitHand();
}
public override void UpdateHand()
{
for (int f = 0; f < fingers.Length; ++f)
{
if (fingers[f] != null)
{
fingers[f].UpdateFinger();
}
}
if (palm != null)
{
Rigidbody palmBody = palm.GetComponent<Rigidbody>();
if (palmBody)
{
palmBody.MovePosition(GetPalmCenter());
palmBody.MoveRotation(GetPalmRotation());
}
else
{
palm.position = GetPalmCenter();
palm.rotation = GetPalmRotation();
}
}
if (forearm != null)
{
// Set arm dimensions.
CapsuleCollider capsule = forearm.GetComponent<CapsuleCollider>();
if (capsule != null)
{
// Initialization
capsule.direction = 2;
forearm.localScale = new Vector3(1f / transform.lossyScale.x, 1f / transform.lossyScale.y, 1f / transform.lossyScale.z);
// Update
capsule.radius = GetArmWidth() / 2f;
capsule.height = GetArmLength() + GetArmWidth();
}
Rigidbody forearmBody = forearm.GetComponent<Rigidbody>();
if (forearmBody)
{
forearmBody.MovePosition(GetArmCenter());
forearmBody.MoveRotation(GetArmRotation());
}
else
{
forearm.position = GetArmCenter();
forearm.rotation = GetArmRotation();
}
}
// This function should link up the position of the physics with the current graphics position
// get the CapusleHand component
CapsuleHand graphics = GetComponentInParent<CapsuleHand>();
// Get the hand from the CapsuleHand
Hand graphics_Hand = graphics.GetLeapHand();
// Assign the palm and forearm transform
forearm.position = graphics_Hand.WristPosition.ToVector3();
palm.position = graphics_Hand.PalmPosition.ToVector3();
}
}
}
I have this code inside of the UpdateHand() function and my hierarchy is shown below.
I've also tried applying the transformation for the transposition in the HandModel itself. However due to function access properties, I would have had to change too much to have those changes propagate to the top level.
To summarize. I've made changes to the CapsuleHand script and the RigidHand script. The changes in the CapsuleHand script shift the hands according to my offset, and the changes in RigidHand should, move my entire physics model to match the graphics model. I noticed that the leap motion fingers are not physics models so when I apply the transposition in CapsuleHand, they also move.
Do you have any suggestions on how to align the whole physics model, (fingers, palm, and forearm) with the graphics model?