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 |