Problems with mouse to actor rotation translation

I’ve been at this problem for a week now, I’m still new to 3D development but I have a good grasp on Vectors and the Rotation class.
I’m currently trying to allow the user to pick up and object, move it into the view of the camera, and have them drag their mouse around to inspect the object.

I have two components on the custom Actor, a Scene component that is the root, and a Static Mesh which is the actual object. When applying Pitch rotation to the Actor, I apply it to the Scene, and when applying Yaw I apply it to the mesh. this way the mesh can be rotated left to right, and the whole Actor can be rotated up and down without being dependent on the Mesh’s rotation.

void AMPlayer::AddControllerYawInput(float value)
{

	if (holding != NULL && LeftMouseDown)
	{
		holding->StaticMeshComponent->SetWorldRotation(holding->StaticMeshComponent->GetComponentRotation().Add(0, -value * 5, 0));
		return;
	}

	if (cameraLock)
	{
		return;
	}

	Super::AddControllerYawInput(value);
}

void AMPlayer::AddControllerPitchInput(float value)
{

	if (holding != NULL && LeftMouseDown)
	{
		float nextVal = holding->RootSceneComponent->GetComponentRotation().Pitch + value * -3;

		// Ry and prevent crazy rotation issues by limit the pitch amount 
		if (nextVal >= 85 || nextVal <= -60)
		{
			return;
		}

		holding->RootSceneComponent->SetWorldRotation(holding->RootSceneComponent->GetComponentRotation().Add(value * -3, 0, 0));
		return;
	}

	if (cameraLock)
	{
		return;
	}

	Super::AddControllerPitchInput(value);
}

The above code checks for mouse input using bools I set, and checks if the Player is currently holding an Actor. I get strange rotation results like this:

Youtube Video of Issue

Any time I move the mouse over and over, the object has “locked” and won’t continue to rotate. I just want simple mouse rotation on this Mesh, but I’m not sure of the best way to execute it.

In UE4, is there a function similar to the Transform.rotation function like in Unity?

Any help is appreciated!

Hi Aaron,

You are using rotator. Rotators have restricted values (Pitch from -90 to 90 degrees). Solution to your problem is to use matrices or quaternions.
Try this code

void ATestActor::Tick(float DeltaSeconds)
{
	Super::Tick(DeltaSeconds);

	auto rot = GetActorRotation();

	FQuat q1 = FQuat(rot); // Current rotator to quaternion
	FQuat q2(FVector(1,0,0), 0.2*DeltaSeconds); // rotate around axis (1,0,0) on angle 0.2*DeltaSeconds
	FQuat qr = q2*q1; // Get result quaternion

	SetActorRotation(qr.Rotator()); // Set quaternion to object
}

Best regards,