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"

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 alt text

90 Degrees Case alt text

180 Degrees Case alt text

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)

Product Version: UE 4.14
more ▼

asked Jul 13 '17 at 09:00 PM in Blueprint Scripting

avatar image

Aeon Softworks
1 1 4

(comments are locked)
10|2000 characters needed characters left

2 answers: sort voted first

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

Floating-point 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 × 10-1. If = 2 and p = 24, then the decimal number 0.1 cannot be represented exactly, but is approximately 1.10011001100110011001101 × 2-4.

more ▼

answered Jul 14 '17 at 12:24 AM

avatar image

Aeon Softworks
1 1 4

(comments are locked)
10|2000 characters needed characters left

I think that is a problem of the way floating-point 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/are-floats-broken-or-is-this-some-precision-issue.html

you might want to know how float values work https://en.wikipedia.org/wiki/Floating-point_arithmetic also: What Every Computer Scientist Should Know About Floating-Point Arithmetic http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

more ▼

answered Jul 14 '17 at 02:17 AM

avatar image

175 7 13 22

avatar image Aeon Softworks Jul 14 '17 at 03:07 AM

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)
10|2000 characters needed characters left
Your answer
toggle preview:

Up to 5 attachments (including images) can be used with a maximum of 5.2 MB each and 5.2 MB total.

Follow this question

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

Answers to this question