# If angle is x to x

### » Mon Oct 12, 2009 3:08 am

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

### » Mon Oct 12, 2009 9:39 am

you could do it like this

B
134
S
65
G
16
Posts: 1,766
Reputation: 19,190

### » Mon Oct 12, 2009 11:02 am

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)

abs(Sprite.Angle - 180) greater or equal 175
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

### » Mon Oct 12, 2009 1:50 pm

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
B
25
S
3
G
6
Posts: 1,197
Reputation: 5,620

### » Mon Oct 12, 2009 3:58 pm

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)
B
52
S
7
G
6
Posts: 1,945
Reputation: 7,610

### » Mon Oct 12, 2009 5:23 pm

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.
Scirra Founder
B
359
S
214
G
72
Posts: 22,952
Reputation: 178,600

### » Mon Oct 12, 2009 7:00 pm

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.
B
161
S
48
G
91
Posts: 7,358
Reputation: 67,271

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

[quote="Ashley":2942rrta]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:2942rrta]
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?
B
23
S
8
G
10
Posts: 1,820
Reputation: 8,242

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

[quote="tulamide":3d0h4nwd]If so, what is the correct way to see if an angle is in between a range of possible angles?[/quote:3d0h4nwd]
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:

[code:3d0h4nwd]+Angle 0 is Clockwise of 340
+Angle 0 is Anticlockwise of 20
-Do things[/code:3d0h4nwd]
Moderator
B
98
S
37
G
19
Posts: 1,584
Reputation: 17,817

### » 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

Next