Rounding error using "move at angle"

Bugs will be moved here once resolved.

Post » Tue Apr 15, 2014 5:16 pm

Problem Description
When moving an object "up" (270º) using the "move at angle" action, the final X position is not consistent. Sometimes you get a rounding error and some times not. The error is related to the initial X position of the object and the distance moved.

For some reason, moving the object "down" (90º), left (0º) or right (180º) doesn't seem to trigger the bug.

Steps to Reproduce Bug
  • Run the project in the debugger
  • See that the sprite's X position (after it has been moved 20 pixels) is 63.99999999999999. This is unexpected.
  • Change the sprite's initial X position in the layout editor to 128
  • Run the project in the debugger
  • See that the sprite's X position (after it has been moved 20 pixels) is 128. This is correct.
  • Change the sprite's initial X position in the layout editor back to 64
  • Disable the second line and enable the first
  • Run the project in the debugger
  • See that the sprite's X position (after it has been moved 19 pixels) is 64. This is correct.

Observed Result
The final X position has a rounding error depending on distance moved and initial X position. The exact values that trigger the bug are somewhat arbitrary.

Expected Result
Since we're moving the sprite exactly 270º (that is, on the vertical axis), the X position should be unaffected.

Affected Browsers
  • Chrome: YES
  • FireFox: YES

Operating System and Service Pack
Windows 7 x64

Construct 2 Version ID
Construct 2 r166 64-bit
You do not have the required permissions to view the files attached to this post.
B
36
S
8
G
8
Posts: 532
Reputation: 6,903

Post » Tue Apr 15, 2014 6:59 pm

Closing as not a bug. It is working correctly. Floating point calculations do not happen with infinite precision. The rounding happens at the level of the CPU circuitry and affects all the software on your computer. You simply have to design your game not to expect exact results.
Scirra Founder
B
387
S
230
G
87
Posts: 24,248
Reputation: 192,226


Return to Closed bugs

Who is online

Users browsing this forum: No registered users and 2 guests