Hello all! I am working on a project in Unreal Engine 4 and I am not exactly sure if I am calculating this correctly. Here is some information on what I am trying to do. Read all the way down to "What needs to be done?" please. I would like to tackle one problem at time. The problem that I am trying to solve right now is rotating a module and moving it so that the attachment points line up correctly and the rotations are the same. This is what I currently have:

float ZRotation = FMath::RadiansToDegrees(acosf(FVector::DotProduct(-ThisAttachmentPoint->GetForwardVector().GetSafeNormal(), OtherAttachmentPoint->GetForwardVector().GetSafeNormal()))) * -FMath::Sign(ThisAttachmentPoint->GetForwardVector().X); AddActorWorldRotation(FRotator(0, ZRotation, 0)); AddActorWorldOffset(OtherAttachmentPoint->GetComponentLocation() - ThisAttachmentPoint->GetComponentLocation());

The way I am moving the object to have the attachment points meet works, but the rotation is proving to be really tricky for me. I thought that I'd have the object rotate first, then move to line up but while this works some ways, other ways it doesn't. I thought the process would be:

- Find the yaw angle between the attachment point's rotation and the object's rotation.
- Add that result to the rotation.
- Move the object so that both attachment points line up.

I can't seem to calculate the 'ZRotation' correctly so that it lines up no matter how I rotate the main module that the new module will attach to. I've also tried this:

float ZRotation = FMath::RadiansToDegrees(FMath::GetAzimuthAndElevation(OtherAttachmentPoint->GetForwardVector().GetSafeNormal(), FVector::ForwardVector, FVector::ZeroVector, FVector::ZeroVector).X - FMath::GetAzimuthAndElevation(-ThisAttachmentPoint->GetForwardVector().GetSafeNormal(), FVector::ForwardVector, FVector::ZeroVector, FVector::ZeroVector).X);

Any help? Thanks!