If angle is x to x

For questions about using Classic.

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

Post » Mon Oct 12, 2009 9:39 am

you could do it like this

B
147
S
73
G
20
Posts: 1,785
Reputation: 22,420

Post » 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)

Instead do a system compare:
abs(Sprite.Angle - 180) greater or equal 175
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » 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
44
S
9
G
9
Posts: 1,222
Reputation: 8,245

Post » 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
75
S
13
G
8
Posts: 1,973
Reputation: 9,841

Post » 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
387
S
230
G
87
Posts: 24,248
Reputation: 192,228

Post » 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.
Image ImageImage
B
168
S
50
G
163
Posts: 8,221
Reputation: 105,061

Post » 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?
Image
B
24
S
8
G
10
Posts: 1,821
Reputation: 8,279

Post » 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
113
S
41
G
20
Posts: 1,586
Reputation: 19,106

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

Return to Help & Support using Construct Classic

Who is online

Users browsing this forum: No registered users and 1 guest