Question by
churu · Feb 12, 2017 at 09:44 PM ·
mathf.clamp
Mouselook not clamping
I'm working on a simple mouse look Script and the camera refuses to clamp no matter what i try.
Here is my script that i've made, there are no errors in the script, yet mouseX is not clamped even tho its in the script clamping it.
public class MouseLook : MonoBehaviour
{
public float sensitivty;
public float minX;
public float maxX;
float mouseX;
float mouseY;
Transform body;
void Start()
{
body = transform.parent;
Cursor.lockState = CursorLockMode.Locked;
Cursor.visible = false;
}
void Update()
{
mouseX = Input.GetAxisRaw("Mouse Y") * sensitivty;
mouseY = Input.GetAxisRaw("Mouse X") * sensitivty;
mouseX = Mathf.Clamp(mouseX, -minX, maxX);
body.rotation *= Quaternion.Euler(0f, mouseY, 0f);
transform.rotation *= Quaternion.Euler(-mouseX, 0f, 0f);
}
}
Thanks in advance to everyone.
Comment
Your answer