- Home /
Limiting X-Axis rotation to 90 degrees and -90 degrees
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; }
}
}
Answer by allenallenallen · Dec 30, 2015 at 04:55 AM
Google is your friend.
http://answers.unity3d.com/questions/659932/how-do-i-clamp-my-rotation.html
Your answer
Follow this Question
Related Questions
need my object to rotate between specific angles on the x axis 2 Answers
Rolling a capsule lengthways, sideways and twisting with AddTorque 1 Answer
The object turn but the axis dont (SOLVED) 3 Answers
Why is this rotation not performed as expected? 1 Answer
Rotate an object's yaw, pitch, and roll relative to the Game Camera Axis. 1 Answer