ID:272591
 
ok well im trying to get a monster to change its looking direction to face the attacker.

so i have a theory to somehow set the M.dir to the opposite of the attackers. so if its West set to East so they will be facing each other. I cant seem to make a formula to get this done other than a bunch of If/then commands.

please help.
Use the get_dir proc :P

EDIT: If you were to use a formula, you would need to use bits. I'm pretty sure dir = ~enemy.dir would work for that (wait no, nevermind; that would only partially work by giving you a lump of every dir that they aren't facing! EX: Northeast to southwest, north to east|south|west).
In response to Jeff8500
my game only uses North, South, East, West
In response to Chase_Hammer
Then create your own get dir proc. If the absolute value of the X distance is greater than the absolute value of the Y distance, then the direction should be north or south. Then its a matter of checking true/false. In my game, I created my own proc to do this, though I'm not especially proud of it >_>
Use a list.

var/list/RevDir = list(2,1,,8,10,9,,4,6,5)


Then set the monster's direction to RevDir[attcker's direction]. If your monster is M and your attacker is A, then you'd use:

M.dir = RevDir[A.dir]


For just N,S,E and W, use this list instead:

var/list/RevCardDir = list(2,1,,8,,,,4,,)
atom/proc/FaceObject(atom/a)
if(istype(a) && a.loc)
//If the argument is an atom and it has a location,
//then make src face the direction from itself to the
//target.
dir = get_dir(src, a)
In response to Xooxer
List? Why not just use the turn() proc?
In response to Popisfizzy
He already said he only wanted the cardinal directions :P
In response to Jeff8500
Well, in that case:
<dm>
atom/proc/FaceObject(atom/a)
if(istype(a) && a.loc)
//If the argument is an atom and it has a location,
//then make src face the direction from itself to the
//target.
dir = get_dir(src, a)

if(dir & (dir - 1))
//If the direction is a diagonal, then turn off
//either north/south or east/west. I chose
//randomness for the hell of it. Just modify
//this to do whatever you feel like.
dir &= ~(prob(50) ? 12 : 3)