Calculating FRotationMatrix that rotates Vector A to align with Vector B in Ue4.

Hey!

I am trying to find the FRotationMatrix that will rotate one vector to align with another. I then want to apply that matrix to another completely different vector, so that both are effectively rotated as a if they were glued together. Basically, this article describes very well the math of it: linear algebra - Calculate Rotation Matrix to align Vector A to Vector B in 3d? - Mathematics Stack Exchange . However, I can not help but think that FRotationMatrix should give me an easier way than to cruely calculate this by hand.

Basically I need some help to understand the features of Unreals Rotators, Quats and RotationMatrix in order to understand what my options are here…

Any help is greatly appreciated : )

Rotator - Utility class for getting/setting rotational information. Can be used to create a Quat.
Quat - Quaternion rotation.
RotationMatrix - A 3x3 rotational matrix (under the hood its actually a 4x4 matrix just without a translation).

A Rotator or a Quat can be used to create a RotationalMatrix which is the actual end product used to create the final transform of an actor.

Rotators are actually incredibly easy to use and you can probably use that to figure out the relative rotation you need to make two entities align. You should be able to simply do TargetRotator - CurrentRotator to get a delta rotator that you could then apply to both entities.

Ah this is great. So if I had Vector A and B, I could get A.Rotation() - B.Rotation() and this is the rotation from B to A I assume?

Yup, then just apply it via AddActorWorldRotation/AddActorLocalRotation depending on what transform space you’re working in.

This is exactly what I’m attempting to do, however, using blueprints - does anyone know which nodes can do this?