# How do I compare angles?

Get help using Construct 2

### » 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
14
G
4
Posts: 1,050
Reputation: 8,205

### » 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
14
G
4
Posts: 1,050
Reputation: 8,205

### » 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
54
S
23
G
18
Posts: 2,123
Reputation: 17,200

### » 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
100
S
38
G
134
Posts: 5,551
Reputation: 85,315

### » 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
14
G
4
Posts: 1,050
Reputation: 8,205

Return to How do I....?

### Who is online

Users browsing this forum: Exabot [Bot] and 6 guests