Example #1
0
        /// <summary>
        /// Apply the rotation inputs, respecting if the moved gameobject is a rigidbody or not. Moves non-kinematic rigidbodies with force,
        /// moves all others with translation. restrictToNstRanges=true will clamp the ranges to the NST and NST Element ranges set for that object,
        /// if any exist. Additionally, even if the objects is a non-kinematic RB, this will still rotate using translate if the rotation type is Euler.
        /// </summary>
        private void ApplyRotation(Vector3 turns)
        {
            // Turn with force only if is a nonKinematic RB and rotation is of the Quat type - otherwise must be moved as euler angles
            if (turnWithForce)
            {
                rb.AddRelativeTorque(turns * turnForce);
                return;
            }

            // Non-Physics-based rotation
            GenericX clamped =
                (restrictToNstRange && re != null && !isQuat) ?
                re.ClampAxes(_gameObject.transform.localEulerAngles + turns * turnRate) :
                _gameObject.transform.localEulerAngles + turns * turnRate;


            if (!isRootGO && re != null)
            {
                re.Apply(clamped);
            }
            // isKinematic ... moverotation otherwise it will studder
            else if (rb == null || translateKinematic)
            {
                _gameObject.transform.localRotation = clamped;
            }
            else
            {
                rb.MoveRotation(clamped);
            }
        }
        /// <summary>
        /// Apply the rotation inputs, respecting if the moved gameobject is a rigidbody or not. Moves non-kinematic rigidbodies with force,
        /// moves all others with translation. restrictToNstRanges=true will clamp the ranges to the NST and NST Element ranges set for that object,
        /// if any exist. Additionally, even if the objects is a non-kinematic RB, this will still rotate using translate if the rotation type is Euler.
        /// </summary>
        private void ApplyRotation(Vector3 turns)
        {
            bool local = (re == null || (re as RotationElement).crusher.local);

            // Turn with force only if is a nonKinematic RB and rotation is of the Quat type - otherwise must be moved as euler angles
            if (turnWithForce)
            {
                rb.AddRelativeTorque(turns * turnForce);
                return;
            }

            GenericX unclamped =
                (isRootGO || !local) ?
                _gameObject.transform.eulerAngles + turns * turnRate :
                _gameObject.transform.localEulerAngles + turns * turnRate;

            // Non-Physics-based rotation
            GenericX clamped = (restrictToNstRange && re != null && !isQuat) ?
                               re.GetCorrectedForOutOfBounds(unclamped) :
                               (Vector3)unclamped;


            if (!isRootGO && re != null)
            {
                re.Apply(clamped);
            }
            // isKinematic ... moverotation otherwise it will studder
            else if (rb == null || translateKinematic)
            {
                if (local)
                {
                    _gameObject.transform.localRotation = clamped;
                }
                else
                {
                    _gameObject.transform.rotation = clamped;
                }
            }

            else
            {
                rb.MoveRotation(clamped);
            }
        }