# If angle is x to x

### » Tue Oct 13, 2009 2:49 am

[quote="Davioware":19dscn59]
Compare

anglediff(sprite.angle,0) Less or equal to 5[/quote:19dscn59]

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
B
7
S
2
G
3
Posts: 139
Reputation: 2,331

### » Tue Oct 13, 2009 3:37 am

[quote="linkman2004":224aate4]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.[/quote:224aate4]
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...
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Tue Oct 13, 2009 8:56 am

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.
Scirra Founder
B
414
S
245
G
92
Posts: 25,188
Reputation: 200,307

### » Tue Oct 13, 2009 10:42 am

[quote="AfterShock":9goveljs]How'd you get five?[/quote:9goveljs]

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.
B
49
S
10
G
9
Posts: 1,224
Reputation: 8,480

### » Tue Oct 13, 2009 9:30 pm

Thanks Ashley and all the others. That's another great plus: With this community, even learning is fun with Construct
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,289

### » Thu Oct 15, 2009 1:23 am

[quote="Ashley":1besz1zi]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.[/quote:1besz1zi]

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.
B
79
S
13
G
8
Posts: 1,977
Reputation: 9,947

Previous