You are on page 1of 1

//find direction from point1 to point2

public function finddir(targetx:number,targety:number):number


{

var disttotarget:number=0;
var tempdir:number=0;
var truey:number=0;
disttotarget = math.sqrt( ((this.x-targetx)*(this.x-targetx)) +
((this.y-targety)*(this.y-targety)) );

if ((targetx-this.x>=0)&&(targety-this.y>=0))
{
truey =((math.asin((targety-
this.y)/disttotarget))*(180/math.pi));
truey = math.abs(truey);
tempdir += (truey);
}
else if ((targetx-this.x<0)&&(targety-this.y>0))
{
truey =((math.asin((targetx-
this.x)/disttotarget))*(180/math.pi));
truey = math.abs(truey);
tempdir += 90+(truey);
}//90-
else if ((targetx-this.x<=0)&&(targety-this.y<=0))
{
truey =((math.asin((targety-
this.y)/disttotarget))*(180/math.pi));
truey = math.abs(truey);
tempdir += 180+(truey)

}//*(-1)
else if ((targetx-this.x>0)&&(targety-this.y<0))
{
truey =((math.asin((targetx-
this.x)/disttotarget))*(180/math.pi));
truey = math.abs(truey);
tempdir += 270+((truey));
}
return tempdir; tempdir;

//move in direction
var fdir,fspeed:number;
public function mid(fdir,fspeed):void
{
/*c2 = a2 + b2
a2 = b2 - c2
a = srt b2 - c2*/

this.y += (math.sin((fdir*(math.pi/180)))*fspeed);
this.x += (math.cos((fdir*(math.pi/180)))*fspeed);

You might also like