コード例 #1
0
    public void GrabUpdate(CustomHand hand)
    {
        GrabUpdateCustom(hand);

        if (GetMyGrabPoser(hand) == triggerPoser)
        {
            trigger.customUpdate(hand);
        }
        if (recoil)
        {
            MyRigidbody.velocity        += transform.TransformDirection(recoil.localPosition / Time.fixedDeltaTime);
            MyRigidbody.angularVelocity += PhysicalObject.GetAngularVelocities(transform.rotation, recoil.rotation, hand.GetBlend());
        }


        RecoilReturn();
    }
コード例 #2
0
ファイル: PhysicalObject.cs プロジェクト: setotj/vrtwix
    public void GrabUpdate(CustomHand hand)
    {
        if (rightHand && leftHand)
        {
            leftIsForvard = transform.InverseTransformPoint(leftMyGrabPoser.transform.position).z > transform.InverseTransformPoint(rightMyGrabPoser.transform.position).z;
            bool leftIsForvardTemp = leftIsForvard;

            if (handleObject != null && handleObject.Count == 2)
            {
                if ((leftHand.Squeeze - rightHand.Squeeze) > SqueezeCheack && rightMyGrabPoser == handleObject[1])
                {
                    handleObject[1].transform.localPosition = new Vector3(0, 0, Mathf.Clamp(transform.InverseTransformPoint(rightHand.GrabPoint()).z, clampHandlePosZ.x, clampHandlePosZ.y));
                    if (leftIsForvard)
                    {
                        leftIsForvard = !leftIsForvard;
                    }
                }
                if ((rightHand.Squeeze - leftHand.Squeeze) > SqueezeCheack && leftMyGrabPoser == handleObject[0])
                {
                    handleObject[0].transform.localPosition = new Vector3(0, 0, Mathf.Clamp(transform.InverseTransformPoint(leftHand.GrabPoint()).z, clampHandlePosZ.x, clampHandlePosZ.y));
                    if (!leftIsForvard)
                    {
                        leftIsForvard = !leftIsForvard;
                    }
                }
            }
            if (useSecondPose && ifUseSecondPose())
            {
                if (secondPoses.Contains(leftHand.grabPoser))
                {
                    MyRigidbody.centerOfMass    = transform.InverseTransformPoint(GetMyGrabPoserTransform(rightHand).position);
                    MyRigidbody.velocity        = (rightHand.PivotPoser.position - GetMyGrabPoserTransform(rightHand).position) / Time.fixedDeltaTime * hand.GetBlend();
                    MyRigidbody.angularVelocity = GetAngularVelocities(rightHand.PivotPoser.rotation, GetMyGrabPoserTransform(rightHand).rotation, hand.GetBlend());
                }
                else
                {
                    MyRigidbody.centerOfMass    = transform.InverseTransformPoint(GetMyGrabPoserTransform(leftHand).position);
                    MyRigidbody.velocity        = (leftHand.PivotPoser.position - GetMyGrabPoserTransform(leftHand).position) / Time.fixedDeltaTime * hand.GetBlend();
                    MyRigidbody.angularVelocity = GetAngularVelocities(leftHand.PivotPoser.rotation, GetMyGrabPoserTransform(leftHand).rotation, hand.GetBlend());
                }
            }
            else
            {
                if (!twoHandTypeOnlyBackHandRotation)
                {
                    leftIsForvardTemp = leftIsForvard;
                }
                if (twoHandTypeMiddleRotation)
                {
                    if (leftIsForvardTemp)
                    {
                        rightHand.ToolTransform.rotation = Quaternion.LookRotation(leftMyGrabPoser.transform.position - rightMyGrabPoser.transform.position, rightMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotRight) + leftMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotLeft));
                        leftHand.ToolTransform.rotation  = Quaternion.LookRotation(leftHand.PivotPoser.transform.position - rightHand.PivotPoser.transform.position, rightHand.PivotPoser.TransformDirection(LocalDirectionWithPivotRight) + leftHand.PivotPoser.TransformDirection(LocalDirectionWithPivotLeft));
                    }
                    else
                    {
                        rightHand.ToolTransform.rotation = Quaternion.LookRotation(rightMyGrabPoser.transform.position - leftMyGrabPoser.transform.position, leftMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotLeft) + rightMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotRight));
                        leftHand.ToolTransform.rotation  = Quaternion.LookRotation(rightHand.PivotPoser.transform.position - leftHand.PivotPoser.transform.position, leftHand.PivotPoser.TransformDirection(LocalDirectionWithPivotLeft) + rightHand.PivotPoser.TransformDirection(LocalDirectionWithPivotRight));
                    }
                }
                else
                {
                    if (leftIsForvardTemp)
                    {
                        rightHand.ToolTransform.rotation = Quaternion.LookRotation(leftMyGrabPoser.transform.position - rightMyGrabPoser.transform.position, rightMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotRight));
                        leftHand.ToolTransform.rotation  = Quaternion.LookRotation(leftHand.PivotPoser.transform.position - rightHand.PivotPoser.transform.position, rightHand.PivotPoser.TransformDirection(LocalDirectionWithPivotRight));
                    }
                    else
                    {
                        rightHand.ToolTransform.rotation = Quaternion.LookRotation(rightMyGrabPoser.transform.position - leftMyGrabPoser.transform.position, leftMyGrabPoser.transform.TransformDirection(LocalDirectionWithPivotLeft));
                        leftHand.ToolTransform.rotation  = Quaternion.LookRotation(rightHand.PivotPoser.transform.position - leftHand.PivotPoser.transform.position, leftHand.PivotPoser.TransformDirection(LocalDirectionWithPivotLeft));
                    }
                }

                if (leftIsForvard)
                {
                    MyRigidbody.centerOfMass    = transform.InverseTransformPoint(rightMyGrabPoser.transform.position);
                    MyRigidbody.velocity        = (rightHand.PivotPoser.position - rightMyGrabPoser.transform.position) / Time.fixedDeltaTime * hand.GetBlend();
                    MyRigidbody.angularVelocity = GetAngularVelocities(leftHand.ToolTransform.rotation, rightHand.ToolTransform.rotation, hand.GetBlend());
                }
                else
                {
                    MyRigidbody.centerOfMass    = transform.InverseTransformPoint(leftMyGrabPoser.transform.position);
                    MyRigidbody.velocity        = (leftHand.PivotPoser.position - leftMyGrabPoser.transform.position) / Time.fixedDeltaTime * hand.GetBlend();
                    MyRigidbody.angularVelocity = GetAngularVelocities(leftHand.ToolTransform.rotation, rightHand.ToolTransform.rotation, hand.GetBlend());
                }
            }
        }
        else            //one hand
        {
            MyRigidbody.centerOfMass    = transform.InverseTransformPoint(GetMyGrabPoserTransform(hand).position);
            MyRigidbody.velocity        = (hand.PivotPoser.position - GetMyGrabPoserTransform(hand).position) / Time.fixedDeltaTime * hand.GetBlend();
            MyRigidbody.angularVelocity = GetAngularVelocities(hand.PivotPoser.rotation, GetMyGrabPoserTransform(hand).rotation, hand.GetBlend());
        }
    }