Clamp without Quaternion?
I tried searching this for quite a while and couldn't get a good answer.
I'm doing an assignment with a third person camera. One of the tasks is to limit the vertical rotation to 180 degrees, that is, clamp from -90 to 90 degrees. Simple enough, using the following code:
private float _xRotation;
public Transform CameraPivot;
private void Update()
{
float mouseY = Input.GetAxis("Mouse Y");
_xRotation -= mouseY;
_xRotation = Mathf.Clamp(_xRotation, -90f, 90f);
CameraPivot.rotation = Quaternion.Euler(_xRotation, 0f, 0f);
}
However, the professor gave us a hint, saying that the solution is much easier if we think outside the box, and not use Quaternions.
Can anyone shed some light on this problem? I've been scratching my head for some time, now, and could not find a solution. At least not one that is simpler than simply using the quaternions.
Thanks in advance and apologies if I left out any relevant information.
You are a using euler angles here, not quaternion. Technically youre using quaternion but really, not consciously at least. You can do this with bare quaternion and it will be a bit more abstract than this.
Your answer
Follow this Question
Related Questions
I want to make a Cube surface 0 Answers
Canon Ball shooting with Instiate 1 Answer
transform.lookat not working? 0 Answers
Clamp transform.rotation? 0 Answers
Clamp transform.rotation? 0 Answers