r81: 8Direction.MovingAngle rounding error

Bugs will be moved here once resolved.

Post » Fri Mar 16, 2012 3:08 am

http://dl.dropbox.com/u/25752478/8dirbug/8dirbug.capx

8Direction.MovingAngle is unpredictable when moving at diagonals, because of what I'd guess to be a float rounding error. To see why this is a problem, walk orthogonally in the demo and move at a diagonal in the opposite direction without stopping.

This bug can be mitigated, but not wholly solved, by using the floor() function; the value returned by MovingAngle can be slightly below the correct value rather than above, and floor() only rounds downward.seven2012-03-16 05:44:06
B
11
S
2
Posts: 35
Reputation: 868

Post » Fri Mar 16, 2012 4:07 am

Have you checked if this was fixed in r8.1?
B
192
S
6
G
7
Posts: 213
Reputation: 10,178

Post » Fri Mar 16, 2012 6:16 am

I ran the update and 8Direction.MovingAngle still returns values like 44.9999... If the player walks diagonally long enough, the value gradually corrects itself, but this takes an unacceptably long time to occur (greater than three seconds). This is probably true for both versions.

Also, rather than having angles more than 180 degrees, the values instead switch to negative numbers (so moving upward is -90 instead of 270, etc.). Here is a quick illustration:

Expected behavior:


In Construct 2:



I understand this is intended behavior and is independent of issues with float rounding, but it's still nonstandard, undocumented behavior, and it works this way for no obvious reason. You can see an example of this making code more complex in the .capx file in the first post.seven2012-03-16 06:17:12
B
11
S
2
Posts: 35
Reputation: 868

Post » Fri Mar 16, 2012 4:20 pm

This is not a bug, it is simply the fact floating point calculations are not always exactly precise. You should not rely on floating point numbers being exact, and this is not specific to Construct 2, it's a general rule when using computers. The solution is just to round() the number and you'll get a more stable result.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

Post » Fri Mar 16, 2012 10:34 pm

@ashley when 'export bug' will be repaired?
B
170
S
3
G
2
Posts: 65
Reputation: 6,057


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 3 guests