# How I can rotate object directly in one side

I need to rotate gameObject (For example simple Cube) directly in one side. So it doesn’t matter how I’ll rotate it editor or by code. I’ll attach screenshots which can help me with explaining

(Red arrows - where I’ll have possible to rotate object, something like that. )

No clue what you’re trying to ask.

2 Likes

I’m sorry, hard to explain in english
Hmm, do you see that white circle for rotating object? You can always rotate object in that circle, like, doesn’t matter how object is rotated right now, it will go straight in that circle’s direction
So I need something like that in code

Do you mean you wish to rotate the object on a set global axis? You can just create a rotation around the direction of your set axis and add that to the current rotation.

How I should create rotation around the direction?

You can use Quaternion.AngleAxis to create an angle around a direction if you wish.

Well, I tried, but I got that:

(if gif don’t works: https://i.gyazo.com/4f12c767e8912b8a3ea6a7c56b0b5fa5.gif)

When I rotated it by Y it started rotate to the right, I need to make it like keep rotating in same direction, no matter how I turn it

Show some code, how are you applying your added rotation? When adding rotations a * b is not the same as b * a.

Here you go:

``````Quaternion rotationX = Quaternion.AngleAxis(anglesToRotate.x * Time.deltaTime, new Vector3(0, 1, 0));
Quaternion rotationY = Quaternion.AngleAxis(anglesToRotate.y * Time.deltaTime, new Vector3(1, 0, 0));
Quaternion rotationZ = Quaternion.AngleAxis(anglesToRotate.z * Time.deltaTime, new Vector3(0, 0, 1));
transform.rotation = transform.rotation * rotationX * rotationY * rotationZ;
``````

anglesToRotate is something like velocity

Calculate your rotation and then add your current rotation to that rather than adding the desired rotation to your current rotation. As I said, a * b does not equal b * a when adding quaternions

Sorry, really hard to understand, heh
What you mean in “Calculate your rotation”?

Ahh! I understand!
Thank you so much!