# How do I calculate the angle difference?

Get help using Construct 2

### » Sun Apr 19, 2015 3:30 pm

Hi!

I want to calculate the angle between a orientated player and a destination - say the minimal angle the player has to turn to point to the destination point (if he has to turn left 0..-180° or turn right 0..180°).

B
43
S
22
G
15
Posts: 391
Reputation: 12,278

### » Sun Apr 19, 2015 3:51 pm

player.angle will give you the angle of the player object
angle(player.x,player.y,destination.x,destination.y) will give you the angle between the player and the destination.

facing right the angle will be 0
facing left the angle will be 180

the difference between the angles will be abs(player.angle-angle(player.x,player.y,destination.x,destination.y)) and abs(angle(player.x,player.y,destination.x,destination.y)-player.angle)

one of these two will be bigger than 180, the other one smaller..
I told my dentist I had trouble with my teeth and asked her to fix it without looking in my mouth..
B
54
S
16
G
8
Posts: 6,160
Reputation: 19,775

### » Sun Apr 19, 2015 7:03 pm

Thanx @LittleStain

B
43
S
22
G
15
Posts: 391
Reputation: 12,278

### » Sun Apr 19, 2015 7:29 pm

Perhaps this is simpler?

R0J0hound wrote:This will give a signed angle diff between two angles.
angle(0,0,cos(a-b),sin(a-b))

It's in the range of -180 to 180. It always picks the shortest distance but it's negative if CCW and positive if CW.

from: angle-difference-in-both-directions_t118900
B
10
S
3
G
2
Posts: 196
Reputation: 2,053

### » Sun Apr 19, 2015 7:43 pm

Dalal wrote:Perhaps this is simpler?

R0J0hound wrote:This will give a signed angle diff between two angles.
angle(0,0,cos(a-b),sin(a-b))

It's in the range of -180 to 180. It always picks the shortest distance but it's negative if CCW and positive if CW.

from: angle-difference-in-both-directions_t118900

Yes - this is the most elegant way
B
43
S
22
G
15
Posts: 391
Reputation: 12,278