2011-02-25 7 views
0

このローテーション機能をダウンさせるのに問題があります。私は別の動く物体に向かって回転するはずのタレットを持っています。それは回転する最短の方向を見つけるはずです。ローテーションの問題

基本的には、アクションスクリプトの回転は、-1 - > -179から180 - > 359を使用して変換されますが、現在、追跡中のオブジェクトがゼロ度の点を通過すると問題が発生します。次に、その電流は他の方向に回転する。

ここにコードがあります。私の心は少し不安を抱いている。

ここ
public function Move(xdiff:Number,ydiff:Number){ 
     var currentRotation:Number; 
     rot = Math.round(Math.atan(ydiff/xdiff) * (180/Math.PI)); 
     if(xdiff < 0){ 
      //this.rotation = 180 + rot; 
      rot = rot + 180 
     }else{ 
      //this.rotation = rot; 
     } 
     if(rot < 0 && rot > -90){ 
      rot = 270 + 90 + rot; 
     } 
     trace("idealrotation: " + rot + "currentrotation: " + rotation); 
     currentRotation = rotation; 
     if(currentRotation < 0){ 
      currentRotation += 360; 
     } 
     if(rot - currentRotation > 0){ 
      if(Math.abs(rot-currentRotation) < 5){ 
       rotation = rot; 
      }else{ 
       rotation += rotationSpeed; 
      } 
     }else if(rot - currentRotation < 0){ 
      if(Math.abs(rot-currentRotation) < 5){ 
       rotation = rot; 
      }else{ 
       rotation -= rotationSpeed; 
      } 
     }else{ 
      rotation = rot; 
     } 

     //this.rotation = rot; 
    } 

答えて

0

が、私はそれをやった方法であるオブジェクト間のx差、とyの差が渡されている:

public function aim(stageX:Number, stageY:Number):void 
{ 
    var angle:Number = (Math.atan2(stageY - y, stageX - x) - Math.PI * 0.5) * 180/Math.PI; 
    if (angle < 180) angle += 360; 
    if (angle > 180) angle -= 360; 
    targetAngle = angle; 
} 

のx、yは大砲、stageXstageY - targetの座標です。

関連する問題