Make Rotator form Z Vector

I am just refactoring some code I prototyped in Blueprint to C++. I have an ImpactNormal that I want to break the Vector Z and Make a Rotator from.

Is this code correct?

FVector ImpactNormal = HitResult.ImpactNormal;
FRotator RotZ = FRotator(ImpactNormal.Z);

Also ran across this:
#include “Kismet/KismetMathLibrary.h”
FRotator RotZ = UKismetMathLibrary::MakeRotFromZ(ImpactNormal);

Are they the same or doing different things?

Edit: Nevermind I answered my own question. I dove into the source code looks like its getting a safe normal then doing a CrossProduct then returning FMatrix

It will work, but just bear in mind that you can control what the rotation ‘around’ the Normal Z axis will be (you need two vectors to force orthogonality). Most of the time though that’s not a concern, especially if you’re just spawning FX or something.

If you want to skip having to include the Kismet Math Library, you can just do this:


FRotator MyRotator = FRotationMatrix::MakeFromZ(ImpactNormal).Rotator()

Since you can (probably) guarantee that the HitResult.ImpactNormal is already normalized, you can save a Square Root calculation as well :slight_smile: