# How do I object angle relations? (315-15 makes no sense)

Get help using Construct 2

### » Thu Jun 08, 2017 3:41 pm

Ho!
I am making a game where car collisions would occur, and to accurately make them, I need to know the angle relations between car A and car B.

Current script takes 2 angle values and if A is within range of (B-10;B+10) then the event occurs. Works fine, just like in situation 1 on the picture. HOWEVER, there is a spot in the angle system where (1-10;1+10) will not describe the angle of car B because it is 359. (shown on the illustration as situation 2)

How do I work around this? (or How do I test whether two objects are rotated towards approx. the same direction)

B
6
S
3
Posts: 139
Reputation: 1,668

### » Thu Jun 08, 2017 5:20 pm

You can use one of the angle compare conditions of the system or sprite object. They handle how angles can wrap around. You could also use the anglediff() expression or if you want the signed angle difference between angles you'd just subtract the angles and normalize the result between -180 to 180.

like this:

diff = a-b
while ( diff<-180) diff +=360
while (diff>180) diff-=360

or this:
angle(0,0,cos(a-b),sin(a-b))
B
100
S
38
G
134
Posts: 5,555
Reputation: 85,323

### » Thu Jun 08, 2017 8:09 pm

Omg thank you for the help.
I'll do exactly that.
B
6
S
3
Posts: 139
Reputation: 1,668