Rotate Actors Relative to Player's view [Like examine object]

Edit: Working Example Project: https://drive.google.com/open?id=0B9mTKNVKB4jddFpuVDRXbjhFZzA

Hi,

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:

132093-a.png

I lock it and I proceed to rotate (only pitch relative to view):

132094-b.png

And I rotate some yaw, also relative to the view:

I’d prefer to use Quaternions, but I can’t figure out the math.

[Few edits later…]

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.

Line 3 should be:
Mesh->AddWorldRotation(DeltaRotation.Rotator());

The AddWorldRotation() function needs a rotator.

It spins but, it’s not relative to the camera view, it’s relative to the world.

Sorry, I might have precipitated my reply without debugging it thoroughly. Let me dig in a bit more.

Edited my last reply, so I’m not sure it notified you, but I think I found the problem.

It’s the same. Apparently, it takes both, FQuat and FRotator.

Interesting. Good to know.

I started a project from scratch and it works now!
Give me a second and I’ll upload it just in case it helps anybody.

Thanks for your help!!

Can you convert your comment into an answer, I can’t set it as answered if it’s a comment.

Sure thing, wasn’t sure if you were going to post you working version as the answer.