Did anyone look into rotating a Pawn in full 3d space (without gimbal lock)? So let’s say you are rotating a spaceship in space.
Right now, I am updating the C++ code. I’ve been replacing the Rotator.Pitch additions with Quaternion math instead. It all pretty much works except for I have a case where my pawn flips over on his head when I hit 90 or -90 degrees I think. Looks like I will have to dig into debugging this deeper
To give more info, in my Character subclass I am setting bUseControllerRotationPitch to true and bUseControllerRotationYaw to true. This way my pawn always rotates with the camera. The Camera can rotate fine in 360 degrees but my Pawn flips
#My Function for you
Yes Adding to rotation can be tricky without quaternions
I wrote a function to streamline the process
//the additive amount of rotation is the expected input (like FRotator(0,3,0) if used in tick
FORCEINLINE void AddToActorRotation(AActor* TheActor, const FRotator& AddRot) const
if (!TheActor) return;
FTransform TheTransform = TheActor->GetTransform();
Ah you have shown me I was approaching the problem the wrong way. I was updating the code to always apply Quaternions. But instead, a much simplier solution is to simply just add the rotation directly to the Actor. Cool, you solved my issue!!! Thank you very much!
Okay I also got my original solution to work as well. For anyone that is curious, I inherited the PlayerController. From there, I overrided AddPitchInput(), AddYawInput(), & AddRollInput(). I replaced all those methods with a Quaternion implementation. In my PlayerCameraManager subclass, I override ProcessViewRotation() and added a Quaternion implementation there as well and normalized my Quat for good measure. In my character subclass, I set bUseController Pitch/Yaw/Roll all to true.
That was pretty much all I had to do. My character now rotates in full 360 deg when set to PHYS_Flying
I’m like beginner level to code really, where would I be putting this function to get my pawn to 360 degree movement? And is there anything else I have to do after I compile it? Cause I did the function but not sure what to do with it now.
would you mind sharing your quaternion implementation? I’m working on a similar project and I’ve been reading on quaternions for far too many hours and gotten none the wiser.
What if you want to do this with the control rotation and not the actor? I need the entire character to rotate including the way in which it handles. I tried doing this
FTransform orgRot(FRotationMatrix::MakeFromZX(GetCapsuleComponent()->GetComponentLocation(), GetCapsuleComponent()->GetForwardVector()).ToQuat());
FQuat addInRot = FRotator(0, mouseX, 0).Quaternion();
and it results in the character turning over on its head as I approach the poles of the world.
can you try to change your line 3 to:
orgRot.SetRotation(addInRot * orgRot.GetRotation());