View Single Post
  #11  
Old 08-26-2007, 04:27 AM
DustyPorViva DustyPorViva is offline
Will work for food. Maybe
DustyPorViva's Avatar
Join Date: Sep 2003
Location: Maryland, USA
Posts: 9,589
DustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond reputeDustyPorViva has a reputation beyond repute
Send a message via AIM to DustyPorViva Send a message via MSN to DustyPorViva
EDIT: here's a fixed version, my mistake!
PHP Code:
function onTimeout() {
  
temp.delta={playerx-x,playery-y,(temp.delta[0]^2+temp.delta[1]^2)^.5}; // get the delta's and distance
  
temp.onwall=i=0// reset i and onwall check
  
while (i<temp.delta[0]) { // while i is less than the distance between player and NPC
    
temp.onwall=onwall(x+(temp.delta[0]/temp.delta[2])*i,y+(temp.delta[1]/temp.delta[2])*i);
    if (
temp.onwall==1) break;
    
i++;
  }

  
setTimer(0.05);

Key mistakes I fixed were resetting i before the loop, or else it'd grow beyond the actual distance! And also fixed the wall check, I was multiplaying i*dx/dy, and that 'cause it to check way farther than needed. You needed to divide the dx/dy by the distance, then multiply by i. This one however doesn't have a check for accuracy, though that would be easy enough to figure out(i+=accuracy )

Last edited by DustyPorViva; 08-26-2007 at 04:39 AM..
Reply With Quote