Hello,
I’ve been having trouble polishing my camera control for my game. It does not have any movement, just camera rotation so the player can look around. I’ve found that when the programs starts, the camera will jump to a random location instead of starting facing forwards. This usually is controlled by the location of the cursor beforehand. Is there any way around this? Code below.
public float mouseSensitivity = 100.0f;
public float clampAngle = 80.0f;
private float rotY = 0.0f; // rotation around the up/y axis
private float rotX = 0.0f; // rotation around the right/x axis
void Start()
{
Vector3 rot = transform.localRotation.eulerAngles;
rotY = rot.y;
rotX = rot.x;
Cursor.visible = false;
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis(“Mouse X”);
float mouseY = -Input.GetAxis(“Mouse Y”);
rotY += mouseX * mouseSensitivity * Time.deltaTime;
rotX += mouseY * mouseSensitivity * Time.deltaTime;
rotX = Mathf.Clamp(rotX, -clampAngle, clampAngle);
Quaternion localRotation = Quaternion.Euler(rotX, rotY, 0.0f);
transform.rotation = localRotation;
}