Download

How does GetActorRotation works in ACharacter?

I had a class derived from APawn, in its ::Tick(float d) there’s been something like this:



FRotator Ang = GetActorRotation();
FRotator RelativeRotation = FRotator(0.0f,30.0f,0.0f);
SetActorRotation(FRotator(0, Ang.Yaw + RelativeRotation.Yaw, 0));

And it has been working fine, the pawn has been turning as it was meant to.

But then I changed the class so it is now derived from ACharacter instead of APawn and everything stopped to work: the Pawn didn’t want to spin further than 30 degrees.
Debug messages have shown me that Ang.Yaw is always zero.
The desription of the GetActorRotation function says it returns the rotation of RootComponent so I guess the problem is this, but can’t figure out what exactly I am doing wrong. Somehow that means that when I actually turn the character its RootComponent is remains still.

Can you print/check the return value of SetActorRotation? Should return a bool on whether it succeeded or not.

Already checked it, it always TRUE. As I said, the Pawn DOES actually turn, the problem is in getting its current rotation.

The only time GetActorRotaion() returns a zero rotator is if the actor has no RootComponent assigned. You could query and verify if RootComponent is null or whether GetActorRotation always returns a zero rotator even after moving and turning around. If that is the case, then that begs the question - how are you initializing your character in the constructor.