private void UpdateHipsRotation()
        {
            HeadTarget headTarget      = hipsTarget.humanoid.headTarget;
            HandTarget leftHandTarget  = hipsTarget.humanoid.leftHandTarget;
            HandTarget rightHandTarget = hipsTarget.humanoid.rightHandTarget;

            if (hipsTarget.hips.target.confidence.rotation < 0.5F)
            {
                Quaternion hipsTargetRotation = hipsTarget.hips.target.transform.rotation;
                Quaternion headTargetRotation = headTarget.head.target.transform.rotation;

                Vector3 neckTargetPosition = headTarget.neck.target.transform.position;

                // still need to add foot based rotation
                if (!(bodyRotation == BodyRotation.HeadRotation) &&
                    (leftHandTarget.hand.target.confidence.rotation > 0.5F && rightHandTarget.hand.target.confidence.rotation > 0.5F))
                {
                    Quaternion newHipsRotation = TorsoMovements.CalculateHipsRotation(hipsTarget.hips.target.transform.position, hipsTargetRotation, leftHandTarget.transform.rotation, rightHandTarget.transform.rotation, hipsTarget.humanoid.leftFootTarget.transform, hipsTarget.humanoid.rightFootTarget.transform, headTargetRotation, neckTargetPosition);
                    hipsTarget.hips.target.transform.rotation = newHipsRotation;
                }
                else
                {
                    Vector3 hipsUpDirection = hipsTarget.humanoid.up;
                    // We need to rotate the head to the up direction to reliably determine the head forward direction
                    Quaternion headBoneRotation  = headTarget.head.bone.targetRotation;
                    Quaternion rotationToUp      = Quaternion.FromToRotation(headBoneRotation * Vector3.up, hipsTarget.humanoid.up);
                    Vector3    hipsBackDirection = -(rotationToUp * headBoneRotation * Vector3.forward);

                    Quaternion q           = Quaternion.LookRotation(hipsUpDirection, hipsBackDirection);
                    Quaternion hipRotation = q * Quaternion.Euler(90, 0, 0);
                    hipsTarget.hips.target.transform.rotation = hipRotation;
                }
            }
            hipsTarget.hips.target.confidence.rotation = 0.2F;
        }
Exemple #2
0
 public override void UpdateMovements(HumanoidControl humanoid)
 {
     TorsoMovements.Update(this);
 }