Here’s how I’m doing it in C++ for now. I think I still need to take gravity into account. There’s some random motion in there even when the device is standing still.
void AODPlayerTurret::SetupPlayerInputComponent(class UInputComponent* InputComponent)
{
InputComponent->BindVectorAxis("RotationRate", this, &AODPlayerTurret::OnRotationInput);
}
void AODPlayerTurret::OnRotationInput(FVector Input)
{
static float DEG_TO_RAD = PI / (180.f);
//TODO: get right and down scale factor from player controller to make the game playable for people who don't want to do full body motions, like while sitting
FQuat RightRot = FQuat(FVector(0.f, 0.f, -1.f), Input.Y * DEG_TO_RAD); //Why is right reversed, I don't know... Damnit MATH!!!!
FQuat DownRot = FQuat(FVector(0.f, 1.f, 0.f), Input.X * DEG_TO_RAD);
FQuat RollLeftRot = FQuat(FVector(1.f, 0.f, 0.f), Input.Z * DEG_TO_RAD);
FQuat Result = GetActorQuat() * RightRot * DownRot * RollLeftRot;
SetActorRotation(Result.Rotator());
}