Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question