0
我正在從事遊戲項目。我有一個場景,其中舞臺將包含隨機位置的圈子。當我按向上箭頭鍵時,我想讓圓圈從中心向三維軸移動。投影設定點
舞臺的寬度爲550和載物臺的高度爲300。
我想是,
位於小於舞臺中心(550/2)的圓應當以小於90度的角度行進,與中心不同。 在圖像的圓圈應角度大於90度,角度較小的行進應該增加基於從中心
- 被定位成比階段的中心更大的圓圈的差(二分之五百五十零)應以大於90度的角度行進,與中心不同。 在圖像的圓圈應在角大於90度,角度越大旅行應該增加基於從中心的差異
我所做的是
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度的角度。請提供我的解決方案找到角度