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)
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.
diff = a-b
while ( diff<-180) diff +=360
while (diff>180) diff-=360
Develop games in your browser. Powerful, performant & highly capable.
Omg thank you for the help.
I'll do exactly that.