- Home /
Trying to understand mouselook script,
So I came across this script while reading a book about unity, and I have to say, it's really confusing to me. I've spent the last day or so trying to understand it, but I wasn't able to.
_rotationX -= Input.GetAxis("Mouse Y") * sensitivityVert;
_rotationX = Mathf.Clamp(_rotationX, minimumVert, maximumVert);
float delta = Input.GetAxis("Mouse X") * sensitivityHor;
float rotationY = transform.localEulerAngles.y + delta;
transform.localEulerAngles = new Vector3(_rotationX, rotationY, 0);
I have two questions to ask about this, that the author didn't really go into.
Are the variables _rotationX and rotationY swapped? Because clearly they take the wrong axes from the mouse.
Why are we decrementing the variable _rotationX? Is there a reason? Every answer is welcomed
,
Answer by Hellium · Jul 03, 2020 at 03:28 PM
No, they aren't swapped.
rotationX
is the rotation around the X axis (the pitch angle), meaning it's the axis used to look up and down, this is why the vertical delta position of the mouse is used.The following image should help you understand.