- Home /
Question by
TrinityTF · Nov 24, 2020 at 10:11 PM ·
clamped rotation
Problem with clamping MouseY rotation.,
Hello, I'm trying to make so the camera would not rotate more then 60↑ -60↓ I'm new to unity and c#, so i don't know how to make this happen My code:
public float mouseSensitivity = 100f;
public Transform playerBody;
public Transform cameraBody;
float lookUpMin = -60;
float lookupMax = 60;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
// Update is called once per frame
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
//mouseY = Mathf.Clamp(mouseY,lookUpMin,lookupMax); <-- I try'd this, didn't work
transform.localRotation = Quaternion.Euler( 26f, 0f, 0f);
playerBody.Rotate(Vector3.up * mouseX);
cameraBody.Rotate(Vector3.right * mouseY);
}
}`
Comment