How do I compare angles?

Get help using Construct 2

Post » Fri May 23, 2014 9:39 pm

I'm trying to create a game that simulate a weighing balance. First I tried using the Physics behavior, but I gave up because I did not know how to adjust parts of the weighing balance (bar, plates, base, etc.). I am now using the Rotate behavior to simulate this and I need to compare the angle to stop the rotation (speed = 0). This action does not exist for the object, so I decided to use the system action: "compare two values". However, it did not work. Any help? Thanks.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Sat May 24, 2014 2:25 pm

I found a better solution: anglelerp (lerp(self.Angle, x, dt). But the question remains: why can not compare angles?
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060

Post » Sat May 24, 2014 4:43 pm

I think the anwser is simple: you cannot define one unique angle, an angle of 90 is as valid as an angle of -270, or even 450, so comparing angles directly is not that meaningful and depending on how some parts of the engine works, the result can be unexpected.
Game design is all about decomposing the core of your game so it becomes simple instructions.
B
53
S
22
G
18
Posts: 2,122
Reputation: 17,123

Post » Sat May 24, 2014 8:19 pm

You could normalize the angle to a range of (-180,180) with angle(0,0,cos(a),sin(a)) before comparison.

Or you could use the sprite condition "is within angle" or "is between angles".

Or you could use the anglediff(a,b) expression to find the angle difference in the range of (0,180).
B
94
S
33
G
114
Posts: 5,360
Reputation: 73,781

Post » Sat May 24, 2014 9:36 pm

R0J0hound wrote:Or you could use the sprite condition "is within angle" or "is between angles".


I tried this but not worked and I don't know why.

@R0J0hound: I'll make some tests with the others suggestions. Thanks.
B
74
S
13
G
4
Posts: 1,006
Reputation: 8,060


Return to How do I....?

Who is online

Users browsing this forum: Christmas, Colludium, irina, minigame and 6 guests