Download

Rotate a character in axis Y

I create a c++ class using the character class as base, now i need the character rotate, i see the rotation in yaw (axis z) and roll (axis x) for all value but for pitch (axis y) only rotate 180º and i need rotate in all grades.

this is the code, only rotate pitch(axis y) because i can´t see the rotation in this axis and in the other axis i see

int grades = 0
FQuat rot;

constructor():

APlayerController* C = UGameplayStatics::GetPlayerController(this, 0); //Control de camara|
C->SetViewTargetWithBlend(this, 0.f,EViewTargetBlendFunction::VTBlend_Linear,0.f,true);|

trick(){
grades++
FRotator gi = FRotator(grades, 0, 0);
FQuat QuatR = FQuat(gi);
rot = QuatR;
this->SetActorRelativeRotation(rot, false, 0, ETeleportType::None)
if (grades >360){grades = 0;}
}

This problem comes from gimbal lock. I believe the controller on a player character has the final say on what rotation a object is. I would recommending rotating the character instead doing something like this. PlayerController->SetControlRotation(OutQuat.Rotator()); It could be that SetActorRelative might also be the problem try using SetActorWorldRotation and do the math yourself.

Heres a little script I made for inspectable objects in my game. Given your players cameras point of view and a object to rotate and input direction, has the math you need.

void AInspectableActor::ArbitraryAxisRotation(const FVector& POVForwardAxis, const FRotator& InputRotation)
{
const FQuat POVQuat = POVForwardAxis.ToOrientationQuat();

const FQuat RollQuat(POVQuat.GetForwardVector(), InputRotation.Roll); // X Axis
const FQuat YawQuat(POVQuat.GetUpVector(), InputRotation.Yaw); // Y Axis
const FQuat PitchQuat(POVQuat.GetRightVector(), InputRotation.Pitch); // Z Axis

const FQuat DeltaQuatToApply = PitchQuat * (YawQuat * RollQuat);

Example use then to rotate object!

//Mesh->SetWorldRotation((DeltaQuatToApply * Mesh->GetComponentQuat()));

Thank you, this it works but i needed add this line. this->BecomeViewTarget(Camara);