EC.ClampUtility.ClampAngleY C# (CSharp) Method

ClampAngleY() public static method

public static ClampAngleY ( float angle, float min, float max ) : float
angle float
min float
max float
return float
        public static float ClampAngleY(float angle, float min, float max)
        {
            if (angle < -180)
            {
                angle += 360;
            }
            if (angle > 180)
            {
                angle -= 360;
            }
            return Mathf.Clamp(angle, min, max);
        }

Usage Example

        private void ProcessOrbit()
        {
            Vector2 incomingInputDelta = new Vector2();

            incomingInputDelta.x = _catcher.PointerEventDataList[0].delta.x * _xSpeed * .02f;
            incomingInputDelta.y = _catcher.PointerEventDataList[0].delta.y * _ySpeed * .02f;

            //dont remember specifics of this
            float momentumWait = Mathf.Clamp(incomingInputDelta.magnitude / 8f, 0f, MaxMomentumWait);

            //if( Mathf.Abs( incomingInputDelta.x ) > Mathf.Abs( inputDelta.x ) )
            if ((_orbitDelta.x > 0 && incomingInputDelta.x > _orbitDelta.x) ||
                (_orbitDelta.x < 0 && incomingInputDelta.x < _orbitDelta.x) ||
                _orbitDelta.x == 0)
            {
                _orbitDelta.x         = incomingInputDelta.x;
                _orbitMomentumTimer.x = momentumWait;
            }
            else if (_orbitMomentumTimer.x <= 0)
            {
                _orbitDelta.x = incomingInputDelta.x;
            }

            if ((_orbitDelta.y > 0 && incomingInputDelta.y > _orbitDelta.y) ||
                (_orbitDelta.y < 0 && incomingInputDelta.y < _orbitDelta.y) ||
                _orbitDelta.y == 0)
            {
                _orbitDelta.y         = incomingInputDelta.y;
                _orbitMomentumTimer.y = momentumWait;
            }
            else if (_orbitMomentumTimer.y <= 0)
            {
                _orbitDelta.y = incomingInputDelta.y;
            }

            Vector3 newRotation = transform.eulerAngles;

            newRotation.y += _orbitDelta.x;
            if (_xMaxLimit != 0 && _xMinLimit != 0)
            {
                newRotation.y = ClampUtility.ClampAngleX(newRotation.y, _xMinLimit, _xMaxLimit);
            }
            transform.eulerAngles = newRotation;
            Vector3 newLocalRotation = transform.localEulerAngles;

            newLocalRotation.x        -= _orbitDelta.y;
            newLocalRotation.x         = ClampUtility.ClampAngleY(newLocalRotation.x, _yMinLimit, _yMaxLimit);
            transform.localEulerAngles = newLocalRotation;
        }
All Usage Examples Of EC.ClampUtility::ClampAngleY