Example #1
0
        private void FixedUpdate()
        {
            if (joint == null)
            {
                return;
            }
            float jointAngle = GetJointAngle();
            bool  flag       = GrabManager.IsGrabbedAny(joint.gameObject);

            if (!grabbed && flag)
            {
                grabbedInGear = gear;
            }
            grabbed = flag;
            if (grabbed)
            {
                if (jointAngle <= (reverseAngle + neutralAngle) / 2f)
                {
                    gear = -1;
                }
                else if (jointAngle <= (neutralAngle + firstAngle) / 2f)
                {
                    gear = 0;
                }
                else if (jointAngle <= (firstAngle + secondAngle) / 2f)
                {
                    gear = 1;
                }
                else
                {
                    gear = 2;
                }
                JointLimits limits = joint.limits;
                limits.min = reverseAngle;
                if (grabbedInGear < 1)
                {
                    if (gear == 2)
                    {
                        gear = 1;
                    }
                    limits.max = firstAngle;
                }
                else
                {
                    limits.max = secondAngle;
                }
                joint.SetLimits(limits);
                if (steeringWheel != null)
                {
                    JointSpring spring = steeringWheel.spring;
                    spring.spring        = ((gear != 2) ? centeringSpring1st : centeringSpring2st);
                    steeringWheel.spring = spring;
                }
            }
            float       value   = 0f;
            JointSpring spring2 = joint.spring;

            switch (gear)
            {
            case -1:
                spring2.targetPosition = reverseAngle;
                value = reverseValue;
                break;

            case 0:
                spring2.targetPosition = neutralAngle;
                value = 0f;
                break;

            case 1:
                spring2.targetPosition = firstAngle;
                value = firstValue;
                break;

            case 2:
                spring2.targetPosition = secondAngle;
                value = secondValue;
                break;
            }
            joint.SetSpring(spring2);
            output.SetValue(value);
        }