Question by
Semius · Mar 10, 2017 at 10:05 PM ·
c#scripting problem
How do I get rotation to not jump?
Hi there! I'm having an issue with object rotation. I have a camera attached to an invisible game object, and I'm trying to get the object to rotate according to mouse input, as is done in first-person RPG's and FPS's. The object is rotating according to input and all, but the problem is that whenever eulerAngles.x passes 0 the rotation jumps to 85. Any help is greatly appreciated!
void Start () {
parent = GameObject.Find("Player");
transform.eulerAngles = new Vector3(0, 0, 0);
}
void FixedUpdate () {
transform.position = new Vector2(parent.transform.position.x, parent.transform.position.y);
}
void LateUpdate() {
float yRot = Input.GetAxis("Mouse X") * Sensitivity;
float xRot = Input.GetAxis("Mouse Y") * Sensitivity;
transform.eulerAngles = new Vector2(transform.eulerAngles.x - xRot, transform.eulerAngles.y + yRot);
if (transform.eulerAngles.x > 85)
{
transform.eulerAngles = new Vector2(85, transform.eulerAngles.y + yRot);
}
else if (transform.eulerAngles.x < -85)
{
transform.eulerAngles = new Vector2(-85, transform.eulerAngles.y);
}
mouseInput = new Vector2(Input.GetAxis("Mouse X"), Input.GetAxis("Mouse Y"));
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612112903im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
How to add a Type to a Class in Javascript? 1 Answer
increase score with a variable from another script 1 Answer
Generating random points and instantiating prefabs with a set distance 0 Answers
How to set a variable of a non-monobehavior script from a monobehaviour script 0 Answers
UI buttons won't recognize script 0 Answers