2017-07-07 7 views
0

ゲームプロジェクトに取り組んでいます。ステージにはランダムな位置に円が含まれるシナリオがあります。上向きの矢印キーを押すと、円が中心から3次元の軸に移動します。投影の設定点

ステージの幅が550であり、ステージの高さが何をしたいことである300

ある、

  • ステージの中心に等しく配置される円(550/2)は90度移動すべきである。 In the above image the circle falls within the center so I want it to travel in 90 degree

  • ステージの中心(550/2)よりも小さい位置にある円は、中心から90度未満の角度で移動する必要があります。円は90度の角度よりも小さい角度で走行すべき画像でIn the image the circles should travel in angle lesser than 90 degree and the angle should vary based on the difference from the center を(2分の550中心

  • ステージの中心よりも大きい位置している円の差に基づいて増加するはずです)は、90度以上の角度で移動し、中心からのずれがあります。 円は角度でより大きく90度と角度を移動する必要がある画像でIn the image the circles should travel in angle greater than 90 degree and the angle should vary based on the difference from the center は中心からの差に基づいて

を増やす必要があり、私がやったことは、私はいけない

var stage_width = 550; 
var stage_height = 300; 
var stage_center = stage_width/2; 
var speed = 5; 
var default_angle = 90 * Math.PI/180; 

for(i = 0; i< 1; i++) 
{ 
    var circle = _root.attachMovie('circle','circle_mc_'+i,_root.getNextHighestDepth()); 
    circle._x = Math.floor(Math.random() * 551); 
    circle._y = Math.floor(Math.random() * 301); 
    circle.obj_x = circle._x; 
    circle.onEnterFrame = function() 
    { 
     Key.addListener(this); 
     this.onKeyDown = function() 
     { 
      if(Key.UP == Key.getCode()) 
      { 
       if(this._x == stage_center) 
       { 
        this._x = this._x + Math.cos(default_angle) * speed; 
        this._y = this._y + Math.sin(default_angle) * speed; 
       } 
       else if(this._x > stage_center) 
       { 
        var diff = this.obj_x - stage_center; 
        // I need a solution here to find the angle 
        var angle = ((90 - diff)<0)?-(90 - diff): 90 - diff; 
        var rad = (angle) * Math.PI/180; 
        this._x = this._x + Math.cos(rad) * speed; 
        this._y = this._y + Math.sin(rad) * speed; 
       } 
       else if(this._x < stage_center) 
       { 
        var diff = stage_center - this.obj_x; 
        // I need a solution here to find the angle 
        var angle = ((90 + diff)>180)? 180: 90 + diff; 
        var rad = (angle) * Math.PI/180; 
        this._x = this._x + Math.cos(rad) * speed; 
        this._y = this._y + Math.sin(rad) * speed; 
       } 
      } 
     } 
    } 
} 

ですセンターと割り当てられた位置との差に基づいて、90度より大きいか小さいかの角度を見つける方法を知っています。親指を見つけるための解決策を教えてください。

答えて

0

最も簡単な方法は、あなたの中心の周りに半径550/2の半円を想像することです。そうすると、ボールのX座標が必要な角度のコサインになり、Y座標がサインになります。

さて、Aを言わせて、いくつかの角度によってベクトルを回転させるために、あなただけを掛け左にする必要があります。

|cos(A) -sin(A)| 
|sin(A) cos(A)| 

しかし、COS(A)以降は、Y = Xと罪(A)を=:

|X -Y| 
|Y X| 

(Iは、Y = 0が画面の一番上にある場合、これが動作するように期待する。)

https://en.wikipedia.org/wiki/Rotation_matrix