r81: 8Direction.MovingAngle rounding error

0 favourites
  • 5 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • 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.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Have you checked if this was fixed in r8.1?

  • 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:

    <center>Expected behavior:

    <img src="http://dl.dropbox.com/u/25752478/8dirbug/standard.png" border="0" />

    In Construct 2:

    <img src="http://dl.dropbox.com/u/25752478/8dirbug/inconstruct.png" border="0" />

    </center>

    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.

  • 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.

  • Ashley when 'export bug' will be repaired?

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