# Rotate Actor around socket with Rotator

I am trying to align and snap two actors in runtime(C++) based on sockets.

ActorA->MeshComponentA->SocketA

ActorB->MeshComponentB->SocketB

So, first I translate ActorB to ActorA such that the sockets are at the same location.
And then I need to rotate ActorB such that the socket rotations are aligned.
I think I can find the correct rotation (subtract SocketA rotator from SocketB rotator).
But, how do I then rotate ActorB around the socket location with this rotation?

You probably should use Quaternions.

I’m not 100% sure what you mean. But I’m guessing socket A is pointing in a direction and you want socket B to point in the same direction. Sockets A and B have different translations and orientations to their respective actors.

You can find the quat between the 2 sockets by multiplying the quat socket A by the inverse of quat of socket B.
Myltiply that quat by the quat of actor B. This should give both sockets the same orientation.

The translation of actor B is finding the difference between new location of socket B (that quat * location of socket B) and the location of socket A.

``````FVector socket_a_loc(100, 45, 25);
FVector socket_b_loc(60, -25, 17);
FRotator socket_a_rot(45, 30, -14);
FRotator socket_b_rot(-25, 130, 314);

FQuat that_quat = FQuat(socket_a_rot) * FQuat(socket_b_rot).Inverse();

FRotator should_be_a_rot = FRotator(that_quat * FQuat(socket_b_rot));
FVector b_loc = that_quat * socket_b_loc;
FVector that_translate = socket_a_loc - b_loc;
FVector should_be_a_loc = b_loc + that_translate;
``````

Thanks, I think you understand the problem!

I can’t get it to work though :(…

I tried the following:

(I only have the Socket Transforms and ActorA is stationary)

``````FQuat Rot = SocketBWorldTransform.Rotator().Quaternion() * SocketAWorldTransform.Rotator().Quaternion().Inverse();

ActorB->SetActorRotation(Rot);

ActorB->SetActorLocation(ActorB->GetActorLocation() + (SocketAWorldTransform - SocketBWorldTransform.SetRotation(Rot).GetLocation()));``````

Here they propose a slightly different solution:

I don’t seem to be able to get a stable solution :’(