Using the UE4 Math API in C++

Okay so this is probably a really simple question but I’ll leave it open ended so people can provide helpers for others, I’ll take these and put them on the wiki in an easy to find document as searching for Math, FMath, Vector, Max etc are not the best of search terms across the board for the engine or websites.

My question is how do I do, Max() for a float in UE4 C++? Like I said if anyone wants to chime in with the usage on other math functions while theyre here please feel free.

Hey, FMath::Max will do what you want. It’s actually defined in FGenericPlatformMath, from which FMath is derived

FMath::Max() should do the trick for floats, it’s a template function so should work for any type that overloads the >= operator. For 3D vectors there’s FVector, for 2D vectors there’s FVector2D, and for 4D vectors there’s FVector4, and plenty more under Engine/Source/Runtime/Core/Public/Math.

I did find this but I was having abit of trouble trying to convert this into usage, it actually seems alittle thin for some reason, like there is more in blueprint. I dont know if that has anything to do with GameplayStatics or not.

if((Normal(Velocity) dot vector(P.Rotation)) > 0.45 || (Normal(Velocity) dot vector(P.Rotation)) < 0.45)

So okay, how would I do this one? I have attempted it but so far its a no go, I just cant work out which of what I should be using from FVector. Theres DotProduct or | operator, normalize which seems to take a float not a vector gah.

If P.Rotation is an FRotator then this should work I think:

(Velocity.SafeNormal() | P.Rotation.Vector()) > 0.45f

Or if you prefer to avoid overloaded operators:

FVector::DotProduct(Velocity.SafeNormal(), P.Rotation.Vector()) > 0.45f