mob
animate_movement = 0
icon='Mob.dmi'
proc
px_north()
pixel_y += PX_STEP
if(pixel_y > 32)
y++
pixel_y-=32
px_south()
pixel_y -= PX_STEP
var/turf/T = locate(x,y,z)
world << "Name: [T.name] | Density: [T.density]"
if(!T.density)
if(pixel_y < 32)
y--
pixel_y+=32
px_east()
pixel_x += PX_STEP
if(pixel_x > 32)
x++
pixel_x-=32
px_west()
pixel_x -= PX_STEP
if(pixel_x < 32)
x--
pixel_x+=32
Problem description:
Well I've been messing with pixel based movement and it seems that I have ran into a tiny problem, pixel based collision. For my "px_south()" procedure I am checking for density, now my debug message outputs the density and name perfectly, the things I want dense have a true (density) value yet the mob still moves south, which is what is the problem.
So in general the mob still moves south but the condition is never true so the statements below the condition are never being called and yet it STILL moves.
Another problem: It's not so smooth and is quite slow.
You are changing pixel_y before anything else, so, regardless of whatever else happens, the object will at least appear to move, even if it's just that pixel_y keeps getting smaller but loc never actually changes.
However, there is another issue altogether, or so it appears at first. You're checking to see if you are colliding with something, but you're checking your current location's density, so you're already there by the time you're checking the density.
Is this what you wanted? I suppose, if PX_STEP is guaranteed to be small enough, this will let you start to move into the side of a dense turf and then not move completely into it. I wouldn't think that'd be how you'd want it though.
If you want a normal movement system where it checks to see if you can move somewhere and just doesn't move you at all if so, you will need to find out where you will be if you were to move, check to see if the movement is possible, then only make changes if the movement should be a success.
For example...
Also, after typing that up and re-looking at what you have, I noticed something else. You have if(pixel_y < 32) which, for moving south, should usually be true and therefor usually trigger. Remember, you're subtracting from pixel_y, so pixel_y will be going into the negatives. You want to check if pixel_y is less than -32. You are going to have the same problem with west.
And one last note about my example: instead of checking to see if T!=loc and !T.Enter(src), you could do the following...
(edit)
Don't forget that you can even make your own pixel_Move() or pixel_step() to go with a potential get_pixel_step() that handles all of this. So you could do something like...
Something like that would allow you to just call pixel_Move(PX_STEP, SOUTH) whenever you want to move south, or pixel_Move(PX_STEP, whatever_direction). This does include diagonal movement though.