ID:157298
 
How can I move the client eye to be in front of the mob? Thanks.
mob.client.eye = get_step(mob,mob.dir)


There are issues to tackle with this, though, such as map edges, and updating it every time the player moves. I'll leave that to you to figure out.
In response to Ter13
Well luckily I'll be locking the mobs movement when that happens so that shouldn't be a problem. Is there a way to make it move more then just in front though? I realized that just one tile in front isn't enough.
In response to DisturbedSixx
Use get_step() multiple times.
In response to Garthor
Fast, easy way to implement something like this. This will get the location a number of steps away. Of course, simple binary operations and a single locate would be more efficient.

proc/get_steps(var/atom/O,var/dir,var/count) //count is the number of steps away in the direction we go.
var/atom/R = O
if(dir&&O&&count)
for(var/c=0;c<count;c++)
R = get_step(R,dir)
if(!R)
break
return R
else
return null


The better way to handle this would be this:

proc/get_offset(var/atom/O,var/dir,var/count) //count is the number of steps away in the direction we go.
var/x = O.x + (1*((dir&4)>0)*count + (-1*((dir&8)>0)*count)
var/y = O.y + (1*((dir&1)>0)*count + (-1*((dir&2)>0)*count)
return locate(x,y,O.z)


I'd write it like this, but I wrote the above for readability.

proc/get_offset(var/atom/O,var/dir,var/count) //count is the number of steps away in the direction we go.
return locate(O.x+(1*((dir&4)>0)*count+(-1*((dir&8)>0)*count),O.y+(1*((dir&1)>0)*count+(-1*((dir&2)>0)*count),O.z)


Either way has about the same effect, one just takes a different level of understanding to use. The top solution is what I would call a "beginner's solution", while the bottom solution uses binary operations, and zero recursion. This is the "intermediate solution" as most programmers don't begin to grasp binary operations until after they've pounded their head into the wall for a while.

What this basically does, is splits up the dir var into binary bits. There are 8 possible directions (for the average system), spanning 4 bits in BYOND. These bits are turned on and off to represent directions. Bit 1 implies NORTH, Bit 2 implies SOUTH, 4 EAST, 8 WEST. Since BYOND uses the Cartesian plane I for its tile map coordinate system, West and South are negative, and North and East are positive in a plane that begins at 1,1 and travels only in a positive direction.

What we do with these binary operations "&" is see if the bit is on. A direction for North would look like this: "1000". This means bit #1 is on, and #s 2-4 are off. An AND (&) of the value 1: (1000 & 1000) is equal to 1000, which equates to a value of 1. Same thing for SOUTH: (0100 & 0100)==0100. Therefore, you can use a >0 comparison to test if the returned AND product is greater than 0, meaning that that bit is indeed on. The > operator will either return a 1 or a 0, and will either allow or nullify the operation, making the equation work.