Right now it is based on some sort of world directional value, not relative to any particular object.
Code:
proc/get_angle(mob/a,mob/b)
//first you have to find the distance between the ref and the object
var/dx=(b.x+b.step_x/world.icon_size) - (a.x+a.step_x/world.icon_size)
var/dy=(b.y+b.step_y/world.icon_size) - (a.y+a.step_y/world.icon_size)
//then the angle equals arctan(distx/disty)
return arctan(dx,dy)
proc/arctan(x,y)
//x=clamp(x,1,x)
//y=clamp(y,1,y)
return (y>=0)?(arccos(x/sqrt(x*x+y*y))):(-arccos(x/sqrt(x*x+y*y)))
1. Get the difference between your forward direction angle (you'll need to convert a dir to an angle) and the angle to the target (found using atan2, which is what you have).
2. Use the scalar or vector product of a normalized forward vector and the normalized vector to your target.
I gotta head to class, so I'll explain more later unless someone else does.