Have you considered using the built-in move? I know this probably doesn't fix your current problem but just something that could benefit you down the line.
Here's a little example of what's possible:
PHP Code:
//#CLIENTSIDE
function onCreated() {
showcharacter();
setTimer(0.05);
}
function onTimeout() {
// Move to a random location in 2 seconds.
moveTo(random(0, 64), random(0, 64), 2);
// Wait till movement complete
waitfor(this, "MovementFinished");
// Continue looping
setTimer(0.05);
}
function moveTo(tx, ty, time) {
// Determine Movement Deltas (Final take away Initial)
temp.dx = tx - this.x;
temp.dy = ty - this.y;
// Set New Direction
this.dir = getdir((this.x + dx) - this.x,(this.y + dy) - this.y);
// Set Movement Animation
setcharani("walk", "");
// Move (The 8 at the end is so the MovementFinished event is called)
move(temp.dx, temp.dy, time, 8);
}
function onMovementFinished() {
setcharani("idle", "");
}