I am using a custom MovementComponent where my character aligns to a surface based on changing gravity direction.
The character aligns perfectly to the surface, but I can’t get my quaternion solution to my mouse look working. The idea is that regardless of the world orientation of the character, the mouse look happens in local space. To further explain, the character follows the normal 1st person mouse look rules regardless of the world orientation the character has.
(I’ve disabled the camera locks - Yaw and Pitch are not dealt with in CameraManager::LimitViewPitch and LimitViewYaw,until I can figure the movement out first).
What I’ve tried so far is to replace MyPlayerController::AddPitchInput and MyPlayerController::AddYawInput with a quaternion solution as such:
FQuat ActorRightQuat = FQuat(MyPawn->GetActorRightVector(), 0);
FQuat RotationQuat = FQuat(0, 0, Val, 0);
ActorRightQuat.Normalize();
RotationQuat.Normalize();
FQuat FinalQuat = ActorRightQuat * RotationQuat;
FinalQuat.Normalize();
RotationInput += FinalQuat.Rotator();
That results in a weird jumpy thing. The view rotates 180 degrees in pitch and so the solution doesn’t work. I’ve tried diminishing the value by multiplying it with 0.1f, but it doesn’t seem to get any better. What I’m trying to do with the code, is to get the actor right vector to pitch the character view by the amount of the rotation value around this vector. Also tried to create quaternion from the right vector and the pitch input value (FQuat(ActorRightVector, InputValue)) and using Quaternion.Rotator() to add to the RotationInput, but that results in nothing that works.
I tried several approaches when replacing the CameraManager::ProcessViewRotation. Here is one (that doesn’t work:
FQuat DeltaRotQuatYaw = FQuat(MyPawn->GetActorUpVector(), OutDeltaRot.Yaw);
FQuat DeltaRotQuatPitch = FQuat(MyPawn->GetActorRightVector, OutDeltaRot.Pitch);
FQuat OriginalQuat = FQuat(ActorUpVector, 0);
DeltaRotQuatYaw.Normalize();
OriginalQuat.Normalize();
DeltaRotQuatPitch.Normalize();
OriginalQuat = OriginalQuat \* DeltaRotQuatYaw;
OriginalQuat.Normalize();
OriginalQuat = OriginalQuat \* DeltaRotQuatPitch;
OriginalQuat.Normalize();
FRotator NewRotation;
NewRotation = OriginalQuat.Rotator() * InputScale;
OutViewRotation += NewRotation;
I’ve tried so many things with quaternions, but I can never get this to work. I’d think this was INCREDIBLY simple, but I’ve been at it for a month now with little luck. A bit frustrating. I’ve printed data on the screen that display my inputs, and it seems that everything else is correct (right vectors, up vectors, gravity vectors, inputs etc.), but my quaternion math.
And finally an apology: I posted a similar question some weeks ago, but got no replies, so I thought I’d try to post it again with what I’ve learned so far.