2013-10-26 1 views
0

라인을 가로 질러 움직이는 적을 만들어 플레이어에게 던지려면 어떻게해야합니까? 이미 나는 당신의 묻는는 여러에 소수점 값을 얻는 방법이라고 생각 어떤 각도적 매니저 클래스 AS3

var dx : Number = point1.x - point2.x; 
var dy : Number = point1.y - point2.y; 
var angleInRadians : Number = Math.atan2(dy, dx); 
var andleInDegrees : Number = angleInRadians * (180/Math.PI); 
+0

던지기 만하면 무엇인가를 직선으로 촬영하는 것입니까? 내가 야구를 던지 듯이 던져 버리는 소리가 들려 야합니다. – prototypical

+0

당신의 문제는 무엇입니까? 애니메이션? – Pier

답변

0

을 얻기 위해이 코드를

나는 액션 스크립트 3으로하고 싶어, 나는 이미 enemy_manager 클래스 이 발사체가 발사체를 플레이어쪽으로 향하게합니다. 이를 달성하기위한 코드입니다.

 var projectileSpeed:Number=30 (pixels a second) 
     var dx : Number = point2.x - point1.x; 
     var dy : Number = point2.y - point1.y; 
     var angleInRadians : Number = Math.atan2(dy, dx); 
     var angleInDegrees : Number = angleInRadians * (180/Math.PI); 

     this.directionX = Math.cos(angleInRadians) * projectileSpeed; // Turns the angleInRadians into a decimal value 
     // For example (180 degrees would be 1 PI and the cos() and sin() would make directionX=-1 and directionY=0 
     this.directionY = Math.sin(angleInRadians) * projectileSpeed; 

     projectile.rotation = angleInDegrees; // makes it face where it is going (if you event want this) 
     ... 
     private function loop(e:Event):void { // loop to show the projectile move 
      // Updates the projectile's positions using directionX and directionY 
      projectile.x += directionX; 
      projectile.y += directionY; 
    }