View Single Post
  #2  
Old 02-12-2002, 03:38 AM
G_yoshi G_yoshi is offline
Forbidden
G_yoshi's Avatar
Join Date: Mar 2001
Posts: 7,206
G_yoshi will become famous soon enough
Send a message via AIM to G_yoshi
Re: Local NPC locations

Quote:
Originally posted by Kaimetsu
Let's say I have an NPC that follows a simple movement pattern. It just moves towards the player in a straight line at a fixed speed, like this:

NPC Code:

if(playerenters){showcharacter; setcharani walk,; timeout=0.05;}
if(timeout){
timeout=0.05;
dx=playerx-x; dy=playery-y;
mag=(dx^2+dy^2)^0.5;
x+=dx/mag; y+=dy/mag;
}



Simple stuff. However, I can't use the move command for this since the bad guy's movement changes whenever you move, and if I just let it work on updates from the server then it'll be really horrible-looking (which is why move was created in the first place). So, here's what I propose: A set of variables that define where the NPC is drawn on the clientside (call them drawx and drawy for the sake of argument). These can be changed all the time and stuff by clientside scripts, but whenever the client recieves x/y data from the server, they jump to that x/y. So I could do something like this:

NPC Code:

//#SERVERSIDE
if(created){showcharacter; setcharani walk,; timeout=0.1;}
if(timeout){
timeout=0.1;
dx=players[0].x-x; dy=players[0].y-y;
mag=(dx^2+dy^2)^0.5;
x+=dx/mag; y+=dy/mag;
}
//#CLIENTSIDE
if(timeout||playerenters){
timeout=0.05;
dx=playerx-x; dy=playery-y;
mag=(dx^2+dy^2)^0.5;
drawx+=dx/mag; drawy+=dy/mag;
}



Because then, y'see, the client could make guesses at where the NPC should be at that time. Sometimes these guesses will be wrong, but with simple movement systems they'll usually get it right and it eliminates the jumpy movement stuff. And since it's all clientside, there's no risk of people abusing it in any way to cheat.
Ehem...the comment //#SERVERSIDE does not exist -_-
__________________
Reply With Quote