- Home /
Unity camera spinning around uncontrollably
I'm trying to clamp the camera rotation but when doing so the camera spins out uncontrollably. I tried it with Math.fClamp and another way and both seem to do the exact same thing.
Here is the code that I use: using UnityEngine; using System.Collections;
public class CameraController : MonoBehaviour {
float mRotY;
void Start () {
if(rigidbody)
rigidbody.freezeRotation = true;
if(!Debug.isDebugBuild)
Screen.lockCursor = true;
else
Screen.lockCursor = false;
}
void FixedUpdate () {
mRotY = Input.GetAxis ("Mouse Y") * GameManager.sensitivity * Time.deltaTime;
if(mRotY>270.0f)
mRotY = 270.0f;
if(mRotY<90.0f)
mRotY = 90.0f;
//
transform.Rotate(mRotY, 0.0f,0.0f);
}
}
Comment
Best Answer
Answer by Dave-Hampson · Apr 08, 2014 at 10:08 PM
The problem is you aren't clamping the rotation, you are clamping the speed that the rotation changes.
Also you are setting any rotation speed less than 90 to be equal to 90, hence why the camera spins out.
Your answer

Follow this Question
Related Questions
Multiple Cars not working 1 Answer
Distribute terrain in zones 3 Answers
Full screen camera missing? 3 Answers
how do i make first person character rotate left and right along with camera? 0 Answers