Calculate rotation from component

I am stuck with a seemingly simple problem:
For my VR project, I have physics-based hands that can grab actors in the world. To define the grab position and rotation on an actor, I use hand position components. When grabbing, the grabbed actor should be rotated and moved towards the hand actor, in a way that the
hand positioner component ends up aligned with the grab position component of the hand actor (see image).

Calculating the needed position offset is simple, but calculating the end rotation is something I can’t get right. What I tried is calculating the rotation using UKismetMathLibrary::ComposeRotators(), but the result is not correct.

			BoxHit.Actor->SetActorRotation(	UKismetMathLibrary::ComposeRotators(	GrabPositionComp->GetComponentRotation(),
																					HandPositionerComp->GetRelativeRotation()), ETeleportType::TeleportPhysics);

1 Like

I only ‘do’ blueprints :slight_smile: but I think your problem is because you’re working with relative and world rotation. You need to stick to one or the other, when you’re working with internal, and external objects.

You’d either need to work with both in world space

or local space

Meh, not too sure about the second, without testing it, but it’s along those lines :slight_smile:

2 Likes

Thanks for your response, I solved it by using world rotation and quaternions to calculate the difference:

		BoxHit.Actor->SetActorRotation(GrabPositionComp->GetComponentRotation(), ETeleportType::ResetPhysics);
		const FQuat AddQuat = BoxHit.Actor->GetActorQuat() * HandPositionerComp->GetComponentRotation().Quaternion().Inverse();
		BoxHit.Actor->AddActorWorldRotation(AddQuat, false, nullptr, ETeleportType::ResetPhysics);
3 Likes

Great :sunglasses: