[Solved][partially]How to cycle transform coordinate system using C++/Blueprints

Problem: I want to switch the coordinate system when I call a function. In editor you can use the shortcut Ctrl+` to do this. I want to do the same thing using C++ or blueprints

Why do I need this: I am working on an inspect functionality where I can rotate the object. I use the movement keys(WASD/Arrow Keys) to move the actor. The issue I am facing is that while pressing the W/S key the rotation is vertical in the first case



but it is horizontal in the second case. I want it to be the same type of rotation in both the cases. I found that cycling transform coordinate system fixes it in editor.

Why this happens: From what I am able to observe the reason this happens is because in the second case Roll is the “Up Direction”


whereas in the first case Pitch is the “Up Direction”

After switching/cycling transform coordinate system


Pitch is always the “Up Direction”. This was the only solution I could think of. If there is any alternative method to accomplish this, that would be helpful as well

Code I am using:

	if (Controller != nullptr)
	{
		const FVector2D MoveValue = Value.Get<FVector2D>();
if (MoveActor)
			{
				if (MoveValue.X != 0.0f)
				{
					auto ObjectRotation = FRotator(0, MoveValue.X, 0);
					MoveActor->AddActorLocalRotation(ObjectRotation * -1);				
				}
				if (MoveValue.Y != 0.0f)
				{
					auto ObjectRotation = FRotator(MoveValue.Y, 0, 0);
					MoveActor->AddActorLocalRotation(ObjectRotation * -1);
				}
			}
		}
	}

I fixed this. Let me explain what I did

if (MoveActor)
{
	if (MoveValue.X != 0.0f)
	{
		auto ObjectRotation = FRotator(0, MoveValue.X, 0);
		MoveActor->AddActorWorldRotation(ObjectRotation * -1);
	}
	if (MoveValue.Y != 0.0f)
	{
		auto ObjectRotation = FRotator(MoveValue.Y, 0, 0);
		MoveActor->AddActorWorldRotation(ObjectRotation * -1);
	}
}

But before calling this piece of code make sure that your that your camera does not have its own rotation otherwise that would be taken into account as well and mess up the object rotation.
Controller->SetControlRotation(FRotator(0, 0, 0));
I set my controller rotation since I am using controller rotation for my character. You can do this for your camera component if it is different for you. I tried doing AddActorWorldRotation before as well but not resetting the player camera resulted in only one axis working in the way I wanted.

This solved the issue for me but I still don’t know How to cycle through the coordinate system in game

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.