Problem with FRotator functions

Hi, I am making an Aircraft Simulator. I am facing a lot of problem with FRotator calculations.

To avoid gimbal lock when adding FRotators, I used this

		FRotator CurrentRot = GetActorRotation();
		FTransform RTrans(CurrentRot);

This works ok but there is a slight jerking action when the actor hits the gimbal lock and skips over it.

Oher than that, sometimes I want to change the Roll of the Aircraft when the Yaw changes(giving an tilting action when going sides). But when I change both at the same time, the pitch also changes.

Should I rewrite the whole system using Quaternion? Will that work?

Yes it will :slight_smile:

As the person who wrote the code you are posting above I can verify that STATEMENT REVISED, see here:

In my own multiplayer game which uses physics based skeletal mesh creatures as the playable unit, I found there is an additional issue with FRotator lockups, they happen even more frequently on clients than on the server!

I was getting by with FRotator until I started testing multiplayer, and then I realized I just had to go the Quaternion route.

Is your main unit a skeletal mesh?

Is it simulating physics or not?

**Spherical Interpolation**

I can highly recommend Slerp for your needs



/** Spherical interpolation. Will correct alignment. Output is not normalized. */

static CORE_API FQuat Slerp( const FQuat &Quat1,const FQuat &Quat2, float Slerp );


My own game's development continues happily because I was able to make the switch to quaternion and all the lockup issues disappeared, even in multiplayer with multiple clients all tested on the same machine! :)


Thanks for the reply Rama.

Yup the code which I wrote was written by you How can I avoid Gimble lock when adding 2 rotators - UE4 AnswerHub.
It worked in nearly every case after that. But when making something which was needed to have much more rotational freedom like the aircraft simulator, it didn’t work perfectly.

I was confused if to use rotation matrices or quats.
I have never used quaternions. Lets see how it works out.

Edit… Did you replace the FRotator replication by a custom quat replication?

You can send FQuat over the network :slight_smile:

UFUNCTION(reliable, server, WithValidation)
void SERVER_SetGoalRotation(FQuat NewRot);

If you get a crash related to this though, make sure to set it to a local var before sending it into the Server function: