Angle Comparison odd behavior

0 favourites
  • 5 posts
From the Asset Store
See how your Logical Resolution looks on different devices
  • My apologies if this is a documented/normal behaviour. I could not find anything about this in the Manual/Forums.

    Work around is to use anglediff instead of simply comparing with operators.

    Link to .capx file (required!):

    Steps to reproduce:

    1. Run the capx

    2. Notice that the result of the first comparison is "1" (true) and the second is "0" (false)

    3. Check the objects angle and the comparison code

    Observed result:

    The first comparison is true, and the second is false

    Expected result:

    Both should be true

    Browsers affected:

    This is most likely browser independent

    Operating system & service pack:

    Windows 7 Enterprise SP1

    Construct 2 version:

    116 (64bit)

    Thanks a lot for all the hard work.

  • If you set your text to display Sprite.Angle, you'll notice that the angle is in fact not 60, but 60.00014... etc. It should probably be a whole number, don't know why it isn't.

    You can use int(Sprite.Angle) to round off the value for now though.

  • Yes, I figured as much.

    If you use only functions/methods specifically aimed at angles you should never run into this problem but as soon as you start treating angles as a "normal number" you will probably run into unexpected behaviors like this one.

    The problem is that I cannot figure out if this is a bug or intended. At least I could not find any reference or warning to this behavior.

  • Closing as not a bug: as Nimtrix said the angle is not actually 60, so it is correct that the comparison returns 0.

    The reason why is internally angles are stored as radians, so converting from and to degrees causes slight floating point inaccuracies. This is normal in computing, and the standard thing to do is check if a number is within a range (e.g. abs(value - 60) < 0.01).

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the answer.

    It's probably worth to explain this fact to newcomers somewhere to save them some debug time and to make their lives easier. least this forum thread should pop up now when searching for the issue <img src="smileys/smiley1.gif" border="0" align="middle" />

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