ID:1449526
 
(See the best response by FIREking.)
Problem description:

I want players to be able to hide/run behind buildings and stand in front of them, but when the layer is too high or low they either stand on top of buildings or go under the buildings like a mechanic working on a car. What is the proper layer to use?


This
Your best choice is to separate the object into top and bottom, so the top's layer is higher than mob's layer, and the bottom one is lower.
There's another technique that I find works a bit better.

Basically, you adjust the player's layer based on their y coordinate in the world.

Now, for their overlays, you use FLOAT_LAYER, that way their clothing adjusts with the player's layer.

mob
Move()
. = ..()
if(.)
Moved()
proc
Moved()
src.layer = src.y


Make sure to use FLOAT_LAYER for any clothing you apply to the player, and remember that FLOAT_LAYER-1 means that the clothes will show up above clothes with FLOAT_LAYER as a layer.
Best response
Here's what I use for layering

atom
var standing = 0
var pz = 0 //allows a multi-tile atom to maintain its layer, add 1 to each piece that goes north

proc/update_layer()
if(standing)
layer = MOB_LAYER - (y - pz) / world.maxy
New()
..()
update_layer()

atom/movable
standing = 1

Move()
. = ..()
if(. && standing)
if(dir & SOUTH) update_layer()
else spawn(get_speed_delay(speed)) update_layer()


get_speed_delay() returns how many 1/10ths of a second it takes to move an atom from one tile to another, which allows me to favor an instant timing for south vs a delayed timing for north (typical RPG Maker style).