0 Favourites

Rounding error using "move at angle"

  • 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

  • Construct 3

    Buy Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Buy Now Construct 3 users don't see these ads
  • 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.

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)