If angle is x to x

This forum is currently in read-only mode.
  • I want to compare an angle when it's right (0) but it only compares when it's EXACTLY that. I wan't it to be able to compare about more or less to 5 degrees. So like this:

    /355

    -0

    \5

    anywhere in those angles or between should be possible.

  • you could do it like this

    <img src="http://dl.getdropbox.com/u/1024727/images/likethis.PNG">

  • The example won't work, because both conditions need to evaluate to true for the action to be triggered. And the angle can't be at the same time greater than 355 and lower than 5 (e.g. 3 is lower than 5 but also lower than 355)

    Instead do a system compare:

    abs(Sprite.Angle - 180) greater or equal 175

  • You must also do a for each loop with system compare if you have multiple instances or else it won't pick the right one, which tulamide didn't mention. Here's how i'd do it.

    Compare

    anglediff(sprite.angle,0) Less or equal to 5

  • you could also use vectors to compare the angle, but that might be a bit difficult if you dont understand what vectors are (mathematically, not graphic type vectors like in flash or wtv)

    angle dif should be fine for this tho, and use it in conjunction with compare if angle is clockwise/anticlockwise to conditions if you want a value between different intervals on different sides

    ex: angle diff </= 5

    angle (comparison angle "355 in this case") is anticlockwise to (origin angle "0 in this case")

    angle diff </= 50

    angle (comparison angle "50 in this case") is clockwise to (origin angle "0 in this case")

    so your interval can be controllable on both sides like this, remember angle diff only returns a positive value (dont know why tho, returning a neg would be really handy so you didnt need to waste time with these clockwise conditions)

  • Don't use greater than/less than tests on angles - it never works properly. They always have problems with the crossover between 0/360 degrees. That's what the angle-specific expressions, like anglediff, are for.

  • Perhaps if we had a way to set the default to another angle. I know this really kinda messed me up in the beginning, as I was used having 0 degrees at the top instead of the right.

  • Don't use greater than/less than tests on angles - it never works properly. They always have problems with the crossover between 0/360 degrees. That's what the angle-specific expressions, like anglediff, are for.

    Ashley, I'm afraid I need an explanation here. I think I'm not understanding this right. How can I validate a range of possible angles if greater/lesser than shouldn't be used? Or do you mean that only my direct approach with abs(angle - 180) is the wrong way?

    abs(Sprite.Angle - 180) greater or equal 175 ->not advised, as it does not use angle expressions?

    anglediff(sprite.angle,0) Less or equal to 5 ->not advised, as it does use a "lesser than" test?

    If so, what is the correct way to see if an angle is in between a range of possible angles?

  • If so, what is the correct way to see if an angle is in between a range of possible angles?

    You could use the "Angle is clockwise of..." condition in the system object. Contrary to the name, you can actually check if an angle is counterclockwise of another one as well.

    So to see if an angle is between two other angles, you could use two of these conditions, one seeing if the angle your checking is clockwise of the lower bound and the other seeing if it's counterclockwise of the upper bound. For example:

    +Angle 0 is Clockwise of 340
    +Angle 0 is Anticlockwise of 20
        -Do things[/code:3d0h4nwd]
  • Compare

    anglediff(sprite.angle,0) Less or equal to 5

    How'd you get five? Anyway, here's the file. if you shoot right, do bla. Shoot left do bla. Could you do it for me because I'm hopelessly lost.

    http://www.mediafire.com/?sharekey=2159 ... f6e8ebb871

  • You could use the "Angle is clockwise of..." condition in the system object. Contrary to the name, you can actually check if an angle is counterclockwise of another one as well.

    Ah, thank you, now I see! So, this is to be used always? Even for a simple test of a certain value? I'm asking this, because I use angles very often to trigger actions, so I better change all "Angle Greater than n"-conditions to the "Angle is Clockwise of n"-ones...

  • Yes, you should always use the angle functions for angles - I think in Construct angles can, at times, go over 360 and below 0 anyway (eg. 405 would be 45 degrees) so straight comparison as numbers will never be reliable. However, the angle functions always work properly with any angle inputs, taking in to account wrapping and angles outside the 0-360 range.

    If you want to check if an angle is equal to a number, for example, you'd have to just check the anglediff() expression and see if it is within 1 degree (say) of the desired angle. As mentioned above, both anglediff(46, 45) and anglediff(406, 45) are 1, so it takes in to account wrapping, which you cannot do by ordinary comparisons.

  • How'd you get five?

    I wrote 5 because you said you wanted to check if the angle was equal to the other angle within a range of 5 degrees. Maybe you meant a total of 5 degrees (not 5 on each side, like I wrote), so in that case I should have put 2.5. anglediff() just returns a positive value between 0 and 180, which is the difference between two angles, with the 360 crossover accounted for.

  • Thanks Ashley and all the others. That's another great plus: With this community, even learning is fun with Construct

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Don't use greater than/less than tests on angles - it never works properly. They always have problems with the crossover between 0/360 degrees. That's what the angle-specific expressions, like anglediff, are for.

    dont confuse him though, you still need to use those tests on the anglediff expression.

    the best way to do things would probably be link mans though. since it allows for absolute control like my method and its simpler than my overcomplicated method of the same thing, and im guessing its the least cpu intesive aswell.

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