Hello again!
Today I am having two problems:
1) When this movement was moved to the clientside, movement was quicker, but the npc coordinates were offset by a few pixels, and now will not work on a gmap (the NPC merely sits in the warpto() spot)
2) The NPC sometimes will not cease the walk gani
PHP Code:
function followPlayer(){
pet.dir = player.dir;
if(pet.level.name != player.level.name){
if(!inPrefix(player.level.name) && pet.lvlBlock.index(player.level.name)==-1){
warpto(player.level.name,player.x+(vecx(player.dir))%64,player.y+(vecy(player.dir))%64);
pet.dir = player.dir;
storeLocation();
return;
}else{
pet.state = STAY; //Enum for this is defined elsewhere
return;
}
}
moveTo(player.x+(vecx(player.dir)*-1)%64,player.y+(vecy(player.dir)*-1)%64);
}
function moveTo(lx,ly){
temp.dx = int(pet.x - temp.lx);
temp.dy = int(pet.y - temp.ly);
if(temp.dx in |0, pet.walkSpeed|){
if(temp.dy in |0, pet.walkSpeed|){
setcharani("pet_idle",null);
return;
}
}
setcharani("pet_walk",null);
temp.nx = pet.x;
temp.ny = pet.y;
if(temp.dx != 0){
if(temp.dx > 0){
temp.nx -= 1*(pet.walkSpeed);
}else{
temp.nx += 1*(pet.walkSpeed);
}
}
if(temp.dy != 0){
if(temp.dy > 0){
temp.ny -= 1*(pet.walkSpeed);
}else{
temp.ny += 1*(pet.walkSpeed);
}
}
pet.dir = getdir(-temp.dx,-temp.dy);
temp.e = .0002;//.0002 is the error value between a tile and pos
temp.e2 = this.e*2;
if(!onwall2(temp.nx+pet.atx,temp.ny+pet.aty,pet.wv,pet.hv)){
pet.x = temp.nx;
pet.y = temp.ny;
}else if(!onwall2(temp.nx+pet.atx,pet.y+pet.aty,pet.wv,pet.hv)){
pet.x = temp.nx;
}else if(!onwall2(this.x+pet.atx,temp.ny+pet.aty,pet.wv,pet.hv)){
pet.y = temp.ny;
}
//need to handle water
}
Suggestions?