Question by
kirikar67 · Dec 17, 2019 at 07:37 PM ·
camerarotationeulerangles
Limit camera rotaion on x axis euler angles
I searched everywhere? but i didn't find the answer. How to limit camera rotation on x axis between - 90 and 90 with sych code. Help plis
transform.rotation *= Quaternion.AngleAxis(
-Input.GetAxis("Mouse Y") * _mouseSense,
Vector3.right
);
// Paw
transform.rotation = Quaternion.Euler(
transform.eulerAngles.x,
transform.eulerAngles.y + Input.GetAxis("Mouse X") * _mouseSense,
transform.eulerAngles.z
);
// Return to init position
if (Input.GetKeyDown(_initPositonButton))
{
transform.position = _initPosition;
transform.eulerAngles = _initRotation;
}
Comment
Best Answer
Answer by kirikar67 · Dec 17, 2019 at 07:58 PM
i have found solution in such method
transform.rotation *= Quaternion.AngleAxis(
-Input.GetAxis("Mouse Y") * _mouseSense,
Vector3.right
);
// Paw
transform.rotation = Quaternion.Euler(
transform.eulerAngles.x,
transform.eulerAngles.y + Input.GetAxis("Mouse X") * _mouseSense,
0
);
if (transform.eulerAngles.x > 90 & transform.eulerAngles.x < 180)
{
Debug.Log("90");
transform.rotation = Quaternion.Euler(
90,
transform.eulerAngles.y,
0);
}
if (transform.eulerAngles.x < 270 & transform.eulerAngles.x > 180)
{
Debug.Log("270");
transform.rotation = Quaternion.Euler(
270,
transform.eulerAngles.y,
0);
}
But it has some issue: when player continue mooving mouse, camera starts jumping. How can fix that bug?
Your answer
Follow this Question
Related Questions
Camera X Rotation Problems 0 Answers
UI compass pointing to a 3D object 0 Answers
Clamping Between Two Different Ranges 1 Answer