ID:156390
 
I've been trying to get my mobs to stop moving diagonally and move s, w, e, n to get to me instead.

The codes I've tried stop the mob from moving diagonally, but if I am on a spot diagonally of them, they will ignore me and not come after me. If I am standing directing in front of or to the sides of them, they will chase me like they are supposed to. Is it possible to make them chase after me, even if I'm on a spot that's diagonal from them?

... Or, is there a way to make them just not attack in a diagonal direction?

What I am trying to do is get zombies to puke (as a basic projectile) and make it so they can only puke n,w,e,s so there isn't any diagonally flying puke.

Other than using an existing Pathfinding demo or creating your own pathfinding algorithms, a simple solution would be to replace any attempts to move diagonally with a random attempt at another direction:
Move(loc,dir)
if(dir==NORTHWEST) step(src,pick(NORTH,WEST))
else if(dir==NORTHEAST) step(src,pick(NORTH,EAST))
else if(dir==SOUTHWEST) step(src,pick(SOUTH,WEST))
else if(dir==SOUTHEAST) step(src,pick(SOUTH,EAST))
else ..()


Instead of moving northeast, it will randomly pick to try to move north or east. This is a very basic solution, advanced pathfinding would still be your best bet
In response to Gunbuddy13
That could be massively shortened (and fixed) with some voodoo:

move(newloc, newdir)
var/d = get_dir(src,newloc)
// if d is diagonal
if(d&(d-1))
// pick either the north/south or east/west component
return step(src, d & pick(NORTH|SOUTH, EAST|WEST))
return ..()


I posted a better solution to this a while ago but I don't feel like searching for it myself. Just try searching "author:Garthor diagonal", maybe "cardinal" as well.
In response to Gunbuddy13
I can't believe I couldn't figure that out. God, I'm stupid.
That worked perfectly, thanks man! Now they don't stand there all retarded.


Thanks to both of you actually, both codes did exactly what I needed.

+1 INTERNETS FOR YOUS