【发布时间】:2011-09-25 15:21:23
【问题描述】:
目前我的对象旋转面对另一个对象时遇到问题。目前它工作正常,就像这张图片一样,我在原点的对象将能够旋转并移动到 3 个象限中的对象,除了带有正的象限90度到180度,我的物体在移动到物体时会旋转几个完整的旋转一段时间,有人知道为什么吗?我用来旋转的句子是rotation += (foodLocationDegrees - (rotation - 90)) * .2;,其中食物是使用
var angle:Number = Math.atan2(foodTarget.y - y, foodTarget.x - x);
foodLocationDegrees =Math.floor((angle * 180 / Math.PI));
y 和 x 是鱼的对象,foodtarget 是食物的对象。
public function moveToFood():void
{
var dx:Number = x - _destinationX;
var dy:Number = y - _destinationY;
trace("Food location degree relative to fish mouth "+foodLocationDegrees);
var targetRotation:Number = 0;
if (foodLocationDegrees > 0 && foodLocationDegrees < 90)
{
trace("food is on 1st quadrant of the fish mount");
this.x -= dx / 18;
this.y -= dy / 18;
}else if (foodLocationDegrees > 90 && foodLocationDegrees < 180)
{
trace("food is on 2nd quadrant of the fish mount");
this.x -= dx / 18;
this.y -= dy / 18;
}else if (foodLocationDegrees > -180 && foodLocationDegrees < -90)
{
trace("food is on 3nd quadrant of the fish mount");
this.x -= dx / 18;
this.y -= dy / 18;
}else if (foodLocationDegrees < 0 && foodLocationDegrees > -90)
{
trace("food is on 4nd quadrant of the fish mount");
this.x -= dx / 18;
this.y -= dy / 18;
}
trace("Before adding Rotation " + rotation);
var number:Number = (foodLocationDegrees - (rotation - 90)) * .1;
trace("rotation to add "+number);
rotation += (foodLocationDegrees - (rotation - 90)) * .2;
trace("After adding Rotation " + rotation);
//removing food when both hit boxes hit
if (hit.hitTestObject(foodTarget.hit))
{
foodInPond--;
foodTarget.removeSelf();
}
}
【问题讨论】:
-
PS 我的数学知识很薄弱,因为我没有努力学习数学,公式是从这里提出的答案拼凑而成的,我的数字有点乱,请原谅我。
标签: flash actionscript-3 math flash-cs4