GameObject rotates around global X axis instead of local

I use this code to rotate my GameObject:

 transform.RotateAround(new Vector3(0, 1, 0), horizontalAngle);
 transform.RotateAround(new Vector3(1, 0, 0), -verticalAngle);

Rotation around Y is OK, but around X not - it rotates around global axis. If I change methods to RotateAroundLocal, it still rotates around global X axis. What’s wrong?

2 Answers

2

Take a look at this answer
That should be what you need :slight_smile:

If you are rotating around the x axis, and not the y axis as you request, change the line in that script I linked to above,

from

verticalaxis = transform.TransformDirection(Vector3.up);

to

verticalaxis = transform.TransformDirection(Vector3.right);

Didn't help - this solution rotates around Y instead of X O_o

Did you try changing the axis of the verticalaxis variable? I have updated my answer to specify what to change in that script.

use

Space.Self

Transform.RotateAround doesn't support the Space.Self parameter.