- Home /
Question by
SwirlyMcGee · Dec 16, 2021 at 09:19 PM ·
scripting problemcharacterbeginnercamera rotationclamped rotation
Clamp camera rotation with relative/local orientation?
I'm trying to figure out how to clamp the rotation of my first-person camera. I have a gameobject that controls the rotation of the camera, its child. My game requires odd gravity, so the camera needs to clamp relative to the transform of its parent. So far, I have the relative camera rotation, but I can't clamp the x (right) values. This is what I have now, this is the closest I've come:
void Update()
{
rightMultiplier = Time.deltaTime * Input.GetAxis("Vertical") * sensitivity;
upMultiplier = Time.deltaTime * Input.GetAxis("Horizontal") * sensitivity;
transform.Rotate(0, upMultiplier, 0);
cameraLiteral.transform.Rotate(rightMultiplier, 0, 0);
if (cameraLiteral.transform.rotation.eulerAngles.x > 90) cameraLiteral.transform.rotation = Quaternion.Euler(90, cameraLiteral.transform.localRotation.eulerAngles.y, cameraLiteral.transform.localRotation.eulerAngles.z);
if (cameraLiteral.transform.rotation.eulerAngles.x < -90) cameraLiteral.transform.rotation = Quaternion.Euler(-90, cameraLiteral.transform.localRotation.eulerAngles.y, cameraLiteral.transform.localRotation.eulerAngles.z);
}
What am I missing? Is there a way to clamp the camera while still having a relative orientation? Or do I need a totally new method? Any help is welcome!
Comment