I want the player to be able to rotate actors from the first person’s view. Like if they were examine the objects.
Currently, if I rotate an actor is relative to the world (unless the root component is attached to some other component). I want to implement a functionality that:
1 Character finds an actor to rotate.
2 Character rotates the focused
object using 6 keys to rotate it,
having a total of 3 pair of inputs.
3 The Actor always rotates relative to
the perspective of the FPS.
An example:
I find an actor, like this:
I lock it and I proceed to rotate (only pitch relative to view):
Okay, so ideally you’d want to get the appropriate Up, Right, or Forward axis from the player camera, then rotate the target some angle value with respect to that axis.
In C++…
One of the constructors for an FQuat does so from an Axis and Angle. It’s used in the Kismet math library this way:
FRotator UKismetMathLibrary::RotatorFromAxisAndAngle(FVector Axis, float Angle)
{
FVector SafeAxis = Axis.GetSafeNormal(); // Make sure axis is unit length
// This is what you would likely use from this function
return FQuat(SafeAxis, FMath::DegreesToRadians(Angle)).Rotator();
}
If you get the appropriate Up/Forward/Right vector from the camera to use as your axis, you can get the angle from your input method. Once you’ve created the rotator you can call the AddWorldRotation() function on the item you want to rotate.
Thanks for your reply. I think it pointed me in the right direction.
I have tried this with no success:
FVector SafeAxis = PC->PlayerCameraManager->GetRootComponent()->GetForwardVector().SafeNormal();//One vector per input
FQuat DeltaRotation = FQuat(SafeAxis, FMath::DegreesToRadians(2));//2 Degrees per input received
Mesh->AddWorldRotation(DeltaRotation);//RootComponent of the Mesh I want to examine
I bought this inventory system in the marketplace since it looks like it has a similar behavior,
but it uses a component to attach the actor where is clicked, which is something that I can’t do.