user1332313
user1332313

Reputation: 45

Rotate already rotated object around axis

I have a prefab layer object (rectangle) which is rotated bei some degrees to have the right angle to be seen by my 2d camera.

Now i want to rotate the object by x degrees around the Vector3.up axis.

this.gameObject.transform.RotateAroundLocal(this.gameObject.transform.up,angle);

I also tried Vector3.up as the axis and RotateAround , none of that produces the expected result. It rotates some, but not the correct angle somehow.

Upvotes: 0

Views: 801

Answers (1)

Michael Antipin
Michael Antipin

Reputation: 3532

When it comes to 2D, I usually use orthographic camera looking at XY plane with Z axis pointing away from it. In which case I rotate things as follows:

gameObject.transform.Rotate(0, 0, angle, Space.World);

Which is angle degrees around Z axis clockwise.

In your case, I guess, it would be

gameObject.transform.Rotate(0, angle, 0 Space.World);

Upvotes: 1

Related Questions