Question3r
Question3r

Reputation: 3742

Rotate object horizontally by 90 degrees in Unity

I want to rotate a cube horizontally by 90 degrees. So I would write

transform.Rotate(new Vector3(90, 0, 0));

but this seems to be wrong.

transform.Rotate(new Vector3(0, 90, 0));

and

transform.Rotate(new Vector3(90, 0, 0), Space.World);

and

transform.Rotate(new Vector3(90, 0, 0), Space.Self);

seem to be wrong, too. I just want to rotate it on its own axis.

How can I archieve that =?

enter image description here

Upvotes: 0

Views: 8128

Answers (3)

libra
libra

Reputation: 683

Check the pivot point of your cube if it's imported from somewhere so it's pivot might not be in exactly 0, 0, 0 of the cube, create a new EmptyGameobject in scene, and have the cube as the child of the new obj, adjust it's position so the new gameobject is located at cube's 0,0,0 position.

And then apply rotate it should be fine. (I know the method sounds tricky, however, this is the only legit way of changing gameobject's pivot point in Unity)


About rotation

There's two way of rotating:

If instant rotate you should be fine

Else if you want it to rotate slowly. Use:

transform.Rotate(0, speed * Time.deltaTime, 0, Space.World);

Upvotes: 0

Romeu Temudo
Romeu Temudo

Reputation: 13

vector = Quaternion.Euler(0, -90, 0) * vector; Try this

Upvotes: 0

Mukesh Saini
Mukesh Saini

Reputation: 1498

The cube's center point is not at its geometry's center. Which is making it move while rotating - enter image description here

You need to have the cube's center at it's geometry's center if you want to rotate it around without moving.

Upvotes: 2

Related Questions