ID:145412
 
Code:
obj
Move()
if(src.walkingback) {..();return 0}
if(istype(src,/obj/shadow))
var/prevloc=src.loc
..()
var/prevdir=src.dir
src.loc=prevloc
src.dir=prevdir
if(src.dir==NORTHEAST) {src.walkingback=1;step(src,rand(NORTH,EAST));src.walkingback=0}
if(src.dir==NORTHWEST) {src.walkingback=1;step(src,rand(NORTH,WEST));src.walkingback=0}
if(src.dir==SOUTHEAST) {src.walkingback=1;step(src,rand(SOUTH,EAST));src.walkingback=0}
if(src.dir==SOUTHWEST) {src.walkingback=1;step(src,rand(SOUTH,WEST));src.walkingback=0}
else {src.walkingback=1;step(src,src.dir);src.walkingback=0}
var/obj/a=new/obj/trail(prevloc)
a.dir=turn(src.dir,180)
a.following=src
a.owner=src.shadow
else ..()


Problem description:
Besides this being messy code (Euh, someone explain me how to make it non-messy? o.o;...), what causes the object (/obj/shadow) to hop around in no logical direction at all, untill it comes on a location where it can walk straight to the mob?

I don't understand what your trying to do. Could you maybe explain is better?
In response to Mega fart cannon
Ah, right. I'm trying to disable diagonal movement of /obj/shadow... When their direction is, for example, NORTHEAST, it'll randomly walk NORTH or EAST.
In response to Mysame
Do you mean something like this:

step(src,rand(NORTH,SOUTH,EAST,WEST))


?
In response to Mega fart cannon
Euh, that's what I do, but according to the movement they're going to take (diagonally)..
In response to Mysame
Mysame wrote:
Ah, right. I'm trying to disable diagonal movement of /obj/shadow... When their direction is, for example, NORTHEAST, it'll randomly walk NORTH or EAST.

You can always do this to keep a direction cardinal.

dir &= pick(3, 12)


The resulting direction will always be cardinal.

~~> Unknown Person
In response to Unknown Person
Though, that works, the 'shadow' can be easily fooled if the target runs up/down or left/right a number of times. Is there any way to make it walk the shortest possible path?

Right now it goes like; (U = users, M = target, -|=shadow)
U-------|
|
|
M
, anyway it could go
U-
|-
|-
|---M


I've tryed playing around with the bits a bit, but it just resulted in the shadow walking in non-logical directions, as before...
In response to Mysame
Pathfinding. I suggest you look up information on A*. I think Deadron wrote a library that does it, too.

There would almost certainly be an option to disable diagonal movement for the pathfinding.
In response to Jp
Why does everybody I ask how to do it say A*pathfinding? I don't understand hell of it, I doubt if I ever will. That's why I'm trying to find a less complicated way! :|