Question by
deeme · Feb 21, 2020 at 04:12 PM ·
camera rotatelimitclamped rotation
Limit camera rotation on Y Axis when using a joystick
Hello, I am trying to build a joystick which rotates both player and camera but I am having problems when trying to limit camera rotation on Y Axis(even if swaped for my code), I have tried with Mathf.Clamp but without any positive results. Here is my code:
void Update()
{
float speed = 3.0f;
float xRot = speed * joystickCamera.Vertical;
float yRot = speed * joystickCamera.Horizontal;
if (joystickCamera.Horizontal != 0f || joystickCamera.Vertical != 0f)
{
transform.Rotate(0.0f, yRot, 0.0f); // rotating the player
MainCamera.transform.Rotate(-Mathf.Clamp(xRot, -45, 45), 0f, 0f, Space.Self);
MainCamera.transform.Rotate(0f, yRot, 0f, Space.World);
}
}
Comment