Help with Calculating Transformation

Hello all! I am working on a system for my game that takes modules that I create and snaps them to each other using attachment points. Here is some information about this. I didn’t get any replies here so I took my question over to the GameDev forums and thankfully got a reply. Now I am having trouble calculating the transform correctly. I’ve tried calculating it in the order that he told me to, but it still doesn’t work correctly especially when the module that the new module is being attached to is rotated. Here is what he told me to do:

Tm1  = Tm2 * Ta2 * Ta1_Rotation * inv(Ta1_Translation)

And here is what I have now:

// ThisAttachmentPoint = Ta1
// OtherAttachmentPoint = Ta2
// OtherModule = Tm2

FTransform NewTransform = OtherModule->GetTransform();
NewTransform *= OtherAttachmentPoint->GetRelativeTransform();
NewTransform *= ThisAttachmentPoint->GetRelativeTransform().GetRotation();
NewTransform *= FTransform(ThisAttachmentPoint->GetRelativeTransform().GetLocation()).Inverse();

Does anyone see anything wrong with this or have an idea of why it may not be working? Thanks! :slight_smile:

So I got it almost working correctly now:

FTransform NewTransform = FTransform(ThisAttachmentPoint->GetRelativeTransform().GetTranslation()).Inverse(); 
NewTransform *= ThisAttachmentPoint->GetRelativeTransform().GetRotation();
NewTransform *= OtherAttachmentPoint->GetRelativeTransform(); 
NewTransform *= OtherModule->GetTransform();

The only problem is that if the second attachment point’s rotation is exactly the opposite of the first attachment point’s rotation, this causes it to rotate and collide with the first module almost like they have the same transform. :confused: Here are some photos. I numbered each attachment point on the module I’m trying to connect to help explain my problem.

Attaching Module 2 Attachment Point 2 (Yaw = -90) to Module 1:

Attaching Module 2 Attachment Point 3 (Yaw = -180) to Module 1:

The second module should rotate to look like this:

Any help? Thanks! :slight_smile: