The GetDist Function
This function is designed to get the distance from the baddy's target to the baddy.  After this function has been run, the x distance can be found with this.distx, the y distance is this.disty, and lastly the overall distance is this.dist.
 
function GetDist(){ 
  Hunt()
  this.distx=abs( this.testx-x); 
  this.disty=abs( this.testy-y); 
  this.dist=((this.distx *this.distx)+(this.disty *this.disty))^.5; 
}
First of, before this function can be made useful, it has to call the previous function I mentioned: Hunt().  That is because this function gets the distance to the target found using the Hunt() function.  this.distx is found by getting the absolute value of the x cord of the target (this.testx) and subtracting the x cord of the baddy.  this.disty is found similarly.  By Pythagorean's theorm the overall distance is the square root of: the square of the x distance plus the square of the y distance: c=(a2+b 2)^.5 or c=(aa+bb)^.5
This function will be called before any function that needs to know the distance from the baddy to the target; for example before the movement script, before the script to see where the baddy faces, to make sure the baddy is facing his target when he attacks, and so on.
 
Previous Topic         Home           Next Topic