- Home /
Question by
TangyStupid8 · Jan 11, 2019 at 10:31 PM ·
rotationclamped rotationyaxis
Issue with camera rotating on the Y axis
When I rotate the camera using my script it works fine but when I reach the value I clamped it to the Y axis of my camera just starts rotating and that causes the movement to be weirdly inverted.
Camera camera;
public float xRot;
public float rotateSpeed = 5;
public float mainY = 11;
// Use this for initialization
void Start () {
camera = GetComponent<Camera>();
}
// Update is called once per frame
void Update () {
xRot = Input.GetAxis("Mouse Y") * rotateSpeed;
transform.Rotate(-xRot, 0, 0);
Quaternion q = transform.rotation;
q.eulerAngles = new Vector3(q.eulerAngles.x, q.eulerAngles.y, 0);
float rotY = Mathf.Clamp(q.x, -0.49f, 0.40f);
//print(rotY + " " + xRot);
print(transform.rotation.y);
Quaternion quaternion = q;
quaternion.x = rotY;
transform.rotation = quaternion;
//transform.rotation = q;
if(quaternion.x != 0)
{
print("a");
}
}
Comment
Your answer
![](https://koobas.hobune.stream/wayback/20220612185602im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Limit Rotation of physics object in 2D 1 Answer
Rotate object with mouse 1 Answer
Trouble rotating tank cannon. 0 Answers
Clamp rotation value. 0 Answers
How to lerp rotate the gun to the opposite of ur mouses X position and clamp it 1 Answer