Rotating a mesh along a given axis, then rotate again along a different axis properly

1.7k views Asked by At

I'm working on a block rotation component for my game, and I hit a bit of a snag that I can't figure out. Basically, I want the ability to rotate a mesh component along all three axis. The player will only ever be able to rotate one axis at a time, by 90degrees or -90degrees. I also want the player to always rotate the mesh according to the world's X, Y, and Z axis, not the block's relative axis, which will change as it is rotated. How do I achieve this?

Mesh with no rotation:

Mesh with no rotation.

Mesh rotated 90 degrees CCW along X axis:

Mesh rotated 90 degrees CCW along X axis.

The problem from here, is if I want to rotate the block along the Y axis, instead it will rotate the block along the Z axis, since the block is now rotated. How do I keep new rotations oriented to the world axis, and not the mesh?

1

There are 1 answers

0
stimdealer On

Found the solution for this. I needed a blueprint node called AddWorldRotation. In C++ from the actor or component you would call AddWorldRotation as well. Then you simply input a rotator for what you wish to add to the component's existing rotation.

In my case, rotating 90 degrees along a specific axis would be FRotator(90, 0, 0), FRotator(0, 90, 0), or FRotator(0, 0, 90).