collision with enemy and player...who?

Getting there.

I wouldn’t use math.abs on angleA and angleB. This would convert -1 radians to 1radian, which is a very different angle. To ensure that the angle is positive you could add TWOPI to it, where TWOPI = math.pi * 2. Then you can get modulo TWOPI of the result to ensure the angle isn’t above two pi radians (i.e. 360 degrees). You’d want to do the same for angleAtoB and angleBtoA.

Not too much, but it does leave one small problem… the situation where the difference in angles is very small, but each angle is either side of 0. e.g. 355 degrees, versus 5 degrees ( or whatever the radian equivalent would be). The real difference is 10 degrees, but

(math.abs(angleA-angleAtoB))

would give you 350 instead.

To solve this, you need a check for when the difference is greater than 1 radian ( 180 degrees - if the difference is over this, you know the actual difference must be less). Subtract TWOPI from the difference of the two, get the abs of it and use that as the new difference.