T
T
Topul2022-01-09 12:39:57
C++ / C#
Topul, 2022-01-09 12:39:57

How to limit camera movement in Unity?

Implemented camera movement by swiping across the screen (for a shooter). But I don't know how to limit camera rotation to Y.
Below is the code:

[SerializeField] [Range(0f, 1f)] private float _angularSpeed;

        [SerializeField] private Transform _target;
        [SerializeField] private TouchInput _touchInput;

        public float angleMin;
        public float angleMax;

        private float _angleX;
        private float _angleY;

        float xRotation = 0f;
        private void Start()
        {
            _angleX = transform.rotation.x;
            _angleY = transform.rotation.y;
        }

        private void Update()
        {
            _angleX += _touchInput.Horizontal * _angularSpeed;
            _angleY += _touchInput.Vertical * _angularSpeed;
            transform.position = _target.transform.position;
            transform.rotation = Quaternion.Euler(-_angleY, _angleX, 0);
        }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
F
freeExec, 2022-01-09
@Topul

ЕСЛИ угол_поворота > 90 ТО угол_поворота = 90

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question