So back in UE3, to get a direction between 2 points, and normalize it to use it for other cases such as momentum and such, you used pretty much, Normal(Vector1 - Vector2), then you obtained, a unit vector direction from 2 3d points.
Now i try for instance, (MycppVectorPoint1 - MyCppVectorPoint2 ).Normalize() , or safe normal wich i don’t really know what’s the difference between " safe normal and Normalize and the tolarance, and i don’t get something Normal ?
UnsafeNormal() is faster, but should only be used if you know for sure your vector cannot have a length of zero. Otherwise, use SafeNormal() and pass in a small value for the tolerance, for example 1.e-4f (0.0001). This just means if your vector had a length very close to or equal to zero, you’ll get a zero vector as the result. It avoids division by zero, or precision errors from dividing by a number close to zero.
//this returns new vector that is normalized
FVector DirectionVector = (Actor1Location - Actor2Location ).GetSafeNormal(); //in 4.7 ".SafeNormal()" is deprecated
//This is a member var that does not return anything, and modifies original data
SomeVector.Normalize();
In general I’d encourage the use of SafeNormal() for clarity of your own code when reviewing it later.
I truly got stuck because of the new language and it’s features, is there something else that i need to take in mind " really really " in mind other than it’s complicated object oriented structure ?
Take on small tasks / sample projects and keep growing your knowledge base through experience, and you will feel more and more equipped for larger / more ambitious projects as you go!
Rama
PS: I am also writing a book on UE4 C++ to introduce core gameplay mechanics and a lot of the vector math that you need for AI and custom game mechanics in a 3D game.
GetSafeNormal is named the way it is because it checks to make sure you aren’t going to divide by zero not because you are returning a copy. GetUnsafeNormal also returns a copy but avoids the additional checks. Normalize() will normalize the vector in place but is also “safe” because it checks for divide by zero first.