user11458208
user11458208

Reputation:

How to Rotate camera only in X-axis with mouse click and drag?

How do I rotate camera around the X-axis only?

The below code does not function only in X-axis but in all axes.

void Update()
    {
        if (Input.GetMouseButton(1))
        {
                float XaxisRotation = Input.GetAxis("Mouse X")*rotationSpeed;
               transform.RotateAround (Vector3.right, XaxisRotation);


        }
    }

Upvotes: 0

Views: 406

Answers (1)

user11458208
user11458208

Reputation:

I was using RotateAround() function before so the camera was rotating in all 3 Axes. Using only Rotate() with Vector3.right makes the camera rotate in the X axis only.

void Update()
    {
        if (Input.GetMouseButton(1))
        {
               float XaxisRotation = Input.GetAxis("Mouse X")*10f;
               transform.Rotate (Vector3.right, XaxisRotation);

        }
}

Upvotes: 1

Related Questions