So I am working on a very basic first-person shooter style game. However, my current character who happens to be a capsule is very happy rolling around X-axis and doing frontflips and backflips. I have been researching this a bit, but have been unable to find any code that works to limit this! Help would be appreciated!
Here’s my code:
using UnityEngine;
using System.Collections;
public class MoveWithMouse : MonoBehaviour
{
public float lookSensitivity = 5f;
public float xRotation;
public float yRotation;
public float currentXRotation;
public float currentYRotation;
public float xRotationV;
public float yRotationV;
public float lookSmoothDamp;
// Update is called once per frame
void Update()
{
xRotation -= Input.GetAxis("Mouse Y") * lookSensitivity;
yRotation += Input.GetAxis("Mouse X") * lookSensitivity;
transform.rotation = Quaternion.Euler(xRotation, yRotation, 0);
Cursor.visible = false;
bool esc = Input.GetKey(KeyCode.Escape);
if (esc) { Cursor.visible = true; }
}
}