for(var/mob/M in oview(15))
if(M == dragonRush_target && M.dead)
dragonRush_target = null
else if(M == dragonRush_target)
O = locate(M.x -1, M.y, M.z)
O = locate(M.x +1, M.y, M.z)
walk_towards(src, O, 0, 0.5)
Above, is a quick test I tried to run.. My game is a sidescroller, and I'm trying to make walk_towards() focus on a specific location of the target. So, if walk_towards() is active. I want it to position the reference in front/behind of the of the target, whilst bumping into them. But I can't think of any solutions to this.
See how the loop goes through every atom in view, but only does something if the atom is dragonRush_target? This is like looping through all your friends in your contacts list and calling them to ask "Are you Bob?" Just call Bob instead:
Now notice that we return immediately if dragonRush_target is dead, so we don't need the "else" statement - that code will only ever run if the "return" statement doesn't.
Now let's look at your get_dir statements. Instead of calling get_dir 6 times, we could call it once and store it in a variable like "directionToTarget" and then compare that to the directions. Also, notice that each direction has something in common, either EAST or WEST. BYOND uses bit flags to represent directions, so we can do something called "bit masking" to test if the direction has the EAST (or WEST) bit ON (or OFF). The statement (dir & EAST) will be true if dir is EAST, NORTHEAST, or SOUTHEAST. You can do the same with any of the other three directions.
Now that that's cleaned up, we can see what's going on more clearly. Using M as a variable also becomes redundant - why not just use the variable we already have, dragonRush_target? Also, what does O represent? Variables should be named something that tells the programmer what they represent.
Now the only functional difference between what I've posted and what you posted originally is that yours wouldn't do anything if M (dragonRush_target) wasn't in oview(15), because it looped through everything in oview asking "are you dragonRush_target?" What we can do is check if dragonRush_target is within view, and cancel out if it isn't.
This cleans up the code and make's it spend less processor time, but it doesn't fix any errors. When you execute this code, it should walk the src directly to the goal. If that's not happening, you should tell us what is happening instead.