SetWorldRotation , SetLocalRotation Floating Point discrepancies
Hello there, i am currently going nuts, somehow parts of my code wouldn't work,and i couldn't get to the bottom of it. But then i have noticed that, when i set a specific Yaw amount to a rotator linked to either SetWorldRotation or SetLocalRotation the resulting Object Transform Rotation is wrong, for instance 90 ° is 179.999985 °, and even worse, the value isn't consistent, sometimes is 179.9999854 °. Therefore when, i execute Compare Floats to enact specific behaviour, nothing ever happens, cause numbers are never equal, (except for 0 degrees, that works) Construction Script 90 Degrees Case 180 Degrees Case Now, i need to solve this, i could've got along if the stilted values were consistent, but they are not. I couldn't find anything specific about this issue, and how to solve it. It sounds so silly, yet this nullifies almost the entire behaviour coded afterwards The Rotator return value is 180.0 so the issue must be in SetWorld Rotation and SetLocalRotation And finally, yes, the issue persist also in SetWorldLocationAndRotation I hereby applaud your solution in advance,kind sir or miss CLAP CLAP CLAP, that was really helpful, grateful, I am (Says I from the future)
(comments are locked)

If anybody else has an issue such as that, the workaround is to ditch "Compare Float" and use a Branch in conjunction with "Nearly Equal (float)", that will suffice for comparisons. It is related to the floating point precision error, read BobTheRoss third link for more info on the subject Direct quote from that third link Floatingpoint representations have a base (which is always assumed to be even) and a precision p. If = 10 and p = 3, then the number 0.1 is represented as 1.00 × 101. If = 2 and p = 24, then the decimal number 0.1 cannot be represented exactly, but is approximately 1.10011001100110011001101 × 24.
(comments are locked)

I think that is a problem of the way floatingpoint arythmetics works. I think 90 can only be described aproximatly by a float value. The Unreal interface shows you a 90 as value if you type it in the details panel, but if you print the actor roation you will get the value that really was set. Even more confusing is that unreal will print you a 90.0 if you print a float variable on that you typed in 90. Maybe Unreal is calculating with 64 bit floats internally so it hits the 90 more closely... I can't tell. I also had problems on itrative adding of float values, this shows a workaround https://answers.unrealengine.com/questions/76911/arefloatsbrokenoristhissomeprecisionissue.html you might want to know how float values work https://en.wikipedia.org/wiki/Floatingpoint_arithmetic also: What Every Computer Scientist Should Know About FloatingPoint Arithmetic http://docs.oracle.com/cd/E1995701/8063568/ncg_goldberg.html I have read a part from your third link and the issue seems to be related to base and precision values. Never encountered it before, still, given the link explanation, that must be it. I have found and read that first link while searching for a solution, though instead i landed on using "Nearly equal(float)"function, it works rather well. I am going to put my answer as the solution, since is the one that made the algorithm work, still, i have put an annotation that clearly refers to your answer, cause it is helpful in elucidating the issue, appreciated.
(comments are locked)

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