angle rounding errors?

0 favourites
  • 5 posts
From the Asset Store
7 Errors
$15 USD
7 Errors is a game where you have to find the 7 mistakes before time runs out. Can you find all 7? Have fun looking.
  • I had an object expression that was doing unexpected thing, so I setup a simple mouseover/text object to check what its angle was ingame.

    To my surprise even though I have an object set at 270 deg, it gives a floating point value of 269.9997895409 and one set at 90 deg and the value in game is 90.0002104591.

    Is this expected behaviour, maybe something to do with radians to degrees conversion under the hood? even when I set an explicit value to an integer in game or use the round function, this still happens...except for 0 which remains 0.

    Oh yeah... I had forgotten about the debugger (which is awesome btw) and confirmed the same thing. Addtionally many position values are also floats. Btw, these are object that are not animated, just moved or rotated by integer values in the layout.

    Not sure what the implications of this are? If I am testing an object for an exact integer value of 270 and it is actually 269.9997895409, does C2 round it automatically?

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is expected behaviour. 'Numbers' are generally floats. Either use round(angle) or check if the difference is within some tolerance, abs(270-angle) < 0.01, for example.

  • Ok, thanks blackhornet, that is what I thought. I am used to languages where I explicitly declare a variable as a float or an integer , so I guess C2 sees all numbers as floats. Still seems strange that an angle on a static sprite set at 270 degs in the layout should have a floating point value of 269.9997895409 and not 270.0

    Btw, was just looking at your midi plugin page for C2...looks right up my alley. Have you or any other users made any examples with it that I could checkout?

  • The engine internally uses everything in radians, and there is a small error introduced by the conversion to radians then back to degrees for the debugger. It's normal and you'll see it in any engine or framework you use that supports floating point numbers. It can happen with ordinary numbers as well, e.g. some calculations like 0.1 * 7 can result in something like 0.69999999998 (this happens at the CPU level - so again will happen with any engine/framework). The usual thing to do is check float values are within a small range like blackhornet suggested.

  • By the time I finished the MIDI plugin, I was so fed up with MIDI that I moved on to other things <img src="smileys/smiley29.gif" border="0" align="middle" /> MIDI is still a hassle to use. Despite the initial furor, I haven't heard of anyone else actually using it.

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