Search in
Sort by:

Question Status:

Search help

  • Simple searches use one or more words. Separate the words with spaces (cat dog) to search cat,dog or both. Separate the words with plus signs (cat +dog) to search for items that may contain cat but must contain dog.
  • You can further refine your search on the search results page, where you can search by keywords, author, topic. These can be combined with each other. Examples
    • cat dog --matches anything with cat,dog or both
    • cat +dog --searches for cat +dog where dog is a mandatory term
    • cat -dog -- searches for cat excluding any result containing dog
    • [cats] —will restrict your search to results with topic named "cats"
    • [cats] [dogs] —will restrict your search to results with both topics, "cats", and "dogs"

[Closed] 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.

Product Version: Not Selected
more ▼

asked Apr 15 '14 at 07:46 AM in C++ Programming

avatar image

973 37 11 37

avatar image MonsOlympus Apr 17 '14 at 01:34 AM
 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.

avatar image enlight_2014 Apr 17 '14 at 04:57 AM

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:


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

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

The question has been closed Jan 30 '17 at 01:20 AM by MonsOlympus for the following reason:

The question is answered, right answer was accepted

2 answers: sort voted first

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

more ▼

answered Apr 15 '14 at 08:27 AM

avatar image

BrɑκеPɑd STAFF
1.4k 33 22 78

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

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.

more ▼

answered Apr 15 '14 at 08:50 AM

avatar image

589 30 14 38

avatar image MonsOlympus Apr 15 '14 at 08:56 AM


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.

(comments are locked)
10|2000 characters needed characters left
Viewable by all users

Follow this question

Once you sign in you will be able to subscribe for any updates here

Answers to this question