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度的角度。请提供我的解决方案找到角度