Question by
agenorcjr · Feb 18 at 10:14 AM ·
camera-movementcamera rotate
Clamping rotation angle on the x Axis of a camera with the function transform.Rotate.
public class CameraMovement : MonoBehaviour
{
public float mouseSensitivity = 100f;
public Transform playerBody;
float xRotation;
// Start is called before the first frame update
void Start()
{
Cursor.lockState = CursorLockMode.Locked;
}
void Update()
{
float mouseX = Input.GetAxis("Mouse X") * mouseSensitivity * Time.deltaTime;
float mouseY = Input.GetAxis("Mouse Y") * mouseSensitivity * Time.deltaTime;
xRotation -= mouseY;
transform.Rotate(-mouseY, 0, 0);
playerBody.Rotate(Vector3.up*mouseX);
}
}
So what i tried before was setting the transform.localRotation to a Quaternion, but it breaks my games recoil system, transform.localRotation = Quaternion.Euler(xRotation, 0f, 0f);
i would like some help figuring out a way to clamp the rotation on the X axis of the camera without using transform.localRotation.
Comment
Your answer
Follow this Question
Related Questions
Camera Roll/Headbob? 0 Answers
Top-Down Camera view (with rotation) need help (third person script) 0 Answers
How to prevent camera going into terrain 0 Answers
Locking Camera's rotation on a rolling character 0 Answers
viewing on the Mouse Y axis not working. 0 Answers