Пример #1
0
        protected virtual void FixedUpdate()
        {
            var angle = Mathf.Clamp(Tracker.Angle, MinAngle, MaxAngle);

            minDelta = Math.Abs(MinAngle - angle);
            maxDelta = MaxAngle - angle;

            var force = false;

            if (_joint)
            {
                var angleFromJointCreation = angle - _angleAtCreation;
                var angleDelta             = Mathf.Abs(angleFromJointCreation);

                if (angleDelta > JointResetThreshold)
                {
                    Destroy(_joint);
                    force = true;
                }
            }

            if (!_joint || force)
            {
                if (minDelta < PhysxMaxLimit || maxDelta < PhysxMaxLimit)
                {
                    _joint               = gameObject.AddComponent <ConfigurableJoint>();
                    _joint.axis          = Tracker.AxisOfRotation;
                    _joint.secondaryAxis = Tracker.AxisOfRotation.OrthogonalVector();
                    _joint.LimitAngularXMotion();
                    _joint.connectedBody = ConnectedBody;

                    _angleAtCreation = Tracker.Angle;

                    if (minDelta < PhysxMaxLimit)
                    {
                        _joint.SetAngularXHighLimit(minDelta);
                    }
                    else
                    {
                        _joint.SetAngularXHighLimit(PhysxMaxLimit);
                    }

                    if (maxDelta < PhysxMaxLimit)
                    {
                        _joint.SetAngularXLowLimit(-maxDelta);
                    }
                    else
                    {
                        _joint.SetAngularXLowLimit(-PhysxMaxLimit);
                    }
                }
            }
        }
Пример #2
0
        private void SetupJoint()
        {
            var currentRotation = transform.localRotation;

            transform.localRotation = JointStartRotation;
            Joint = gameObject.AddComponent <ConfigurableJoint>();
            Joint.connectedBody = ConnectedBody;
            Joint.LockLinearMotion();
            Joint.LockAngularYMotion();
            Joint.LockAngularZMotion();

            Joint.axis = Axis.GetVector();

            if (LimitRotation)
            {
                Joint.LimitAngularXMotion();
                Joint.SetAngularXHighLimit(-MinAngle);
                Joint.SetAngularXLowLimit(-MaxAngle);
            }
            else
            {
                Joint.angularXMotion = ConfigurableJointMotion.Free;
            }

            Joint.secondaryAxis = Joint.axis.OrthogonalVector();
            Joint.SetAngularXDrive(Spring, Damper, 10000f);

            transform.localRotation = currentRotation;
        }