コード例 #1
0
        private void SetupRestJoint(HVRArrow arrow)
        {
            _restJoint = gameObject.AddComponent <ConfigurableJoint>();

            var axis = Forward;

            _restJoint.axis          = axis;
            _restJoint.secondaryAxis = axis.OrthogonalVector();

            _restJoint.LockYMotion();
            _restJoint.LockZMotion();

            _restJoint.anchor = transform.InverseTransformPoint(Rest.transform.position);
            _restJoint.autoConfigureConnectedAnchor = false;
            _restJoint.connectedBody   = arrow.Rigidbody;
            _restJoint.connectedAnchor = arrow.transform.InverseTransformPoint(Rest.transform.position);
        }
コード例 #2
0
        private void SetupStringJoint()
        {
            _stringJoint = gameObject.AddComponent <ConfigurableJoint>();

            var axis = Forward;

            _stringJoint.axis          = axis;
            _stringJoint.secondaryAxis = axis.OrthogonalVector();

            _stringJoint.LimitXMotion();
            _stringJoint.LockYMotion();
            _stringJoint.LockZMotion();
            _stringJoint.LockAllAngularMotion();
            _stringJoint.SetXDrive(StringSpring, 0, StringSpring);
            _stringJoint.anchor         = transform.InverseTransformPoint(NockRigidbody.position) - axis * StringLimit;
            _stringJoint.targetPosition = Vector3.right * StringLimit;
            _stringJoint.autoConfigureConnectedAnchor = false;
            _stringJoint.connectedBody   = NockRigidbody;
            _stringJoint.connectedAnchor = Vector3.zero;
            _stringJoint.linearLimit     = new SoftJointLimit()
            {
                limit = StringLimit
            };

            if (StringLimitStyle == HVRBowLimitStyle.Limit)
            {
                _stringLimitJoint = gameObject.AddComponent <ConfigurableJoint>();

                _stringLimitJoint.axis          = axis;
                _stringLimitJoint.secondaryAxis = axis.OrthogonalVector();

                _stringLimitJoint.LimitXMotion();
                _stringLimitJoint.LockYMotion();
                _stringLimitJoint.LockZMotion();
                _stringLimitJoint.LockAllAngularMotion();

                _stringLimitJoint.anchor = transform.InverseTransformPoint(NockRigidbody.position);
                _stringLimitJoint.autoConfigureConnectedAnchor = false;
                _stringLimitJoint.connectedBody   = NockRigidbody;
                _stringLimitJoint.connectedAnchor = Vector3.zero;
                _stringLimitJoint.linearLimit     = new SoftJointLimit()
                {
                    limit = StringLimit
                };
            }
        }
コード例 #3
0
        private void SetupNockJoint(HVRArrow arrow)
        {
            _nockJoint = NockRigidbody.gameObject.AddComponent <ConfigurableJoint>();

            var axis = Forward;

            _nockJoint.axis          = axis;
            _nockJoint.secondaryAxis = axis.OrthogonalVector();
            _nockJoint.LockYMotion();
            _nockJoint.LockZMotion();
            _nockJoint.LockLinearMotion();
            _nockJoint.LockAllAngularMotion();
            _nockJoint.anchor = Vector3.zero;
            _nockJoint.autoConfigureConnectedAnchor = false;
            _nockJoint.connectedBody   = arrow.Rigidbody;
            _nockJoint.connectedAnchor = arrow.NotchPointLocal;
        }
コード例 #4
0
        private void SetupJoint()
        {
            _joint = gameObject.AddComponent <ConfigurableJoint>();
            _joint.connectedBody = ConnectedBody;
            //_joint.anchor = StartPosition;
            _joint.autoConfigureConnectedAnchor = false;

            var worldStartPosition = StartPosition;

            if (transform.parent)
            {
                worldStartPosition = transform.parent.TransformPoint(StartPosition);
            }

            var worldEndPosition = EndPosition;

            if (transform.parent)
            {
                worldEndPosition = transform.parent.TransformPoint(EndPosition);
            }


            if (ConnectedBody)
            {
                _joint.connectedAnchor = ConnectedBody.transform.InverseTransformPoint(worldStartPosition);
            }
            else
            {
                _joint.connectedAnchor = worldStartPosition;
            }

            _joint.SetXDrive(Spring, Damper, Spring);

            _joint.LimitXMotion();
            _joint.LockYMotion();
            _joint.LockZMotion();
            _joint.LockAllAngularMotion();
            _joint.axis          = _axis;
            _joint.secondaryAxis = _joint.axis.OrthogonalVector();
            _joint.SetLinearLimit(Vector3.Distance(StartPosition, EndPosition));

            _limitJoint = gameObject.AddComponent <ConfigurableJoint>();
            _limitJoint.connectedBody = ConnectedBody;
            //_limitJoint.anchor = EndPosition;
            _limitJoint.autoConfigureConnectedAnchor = false;

            if (ConnectedBody)
            {
                _limitJoint.connectedAnchor = ConnectedBody.transform.InverseTransformPoint(worldEndPosition);
            }
            else
            {
                _limitJoint.connectedAnchor = worldEndPosition;
            }

            _limitJoint.LockYMotion();
            _limitJoint.LockZMotion();
            _limitJoint.LockAllAngularMotion();
            _limitJoint.axis          = _axis;
            _limitJoint.secondaryAxis = _joint.axis.OrthogonalVector();
            _limitJoint.LimitXMotion();
            _limitJoint.SetLinearLimit(Vector3.Distance(StartPosition, EndPosition));
        }
コード例 #5
0
 public static void LockLinearMotion(this ConfigurableJoint joint)
 {
     joint.LockXMotion();
     joint.LockYMotion();
     joint.LockZMotion();
 }