gpt4 book ai didi

flash - Adobe Flash cs4 旋转数学

转载 作者:行者123 更新时间:2023-12-05 01:12:22 26 4
gpt4 key购买 nike

我目前遇到了我的对象旋转面对另一个对象的问题。目前它工作正常,如图所示,我在原点的对象将能够旋转并移动到 3 个象限中的对象,除了具有正数的象限90度到180度,我的物体在移动到物体时会旋转几个完整的旋转一段时间有人知道为什么吗?我用来旋转的句子是 rotation += (foodLocationDegrees - (rotation - 90)) * .2; which food is calculated using

var angle:Number = Math.atan2(foodTarget.y - y, foodTarget.x - x); 
foodLocationDegrees =Math.floor((angle * 180 / Math.PI));

y 和 x 是鱼的对象,foodtarget 是食物的对象。

http://iepro.files.wordpress.com/2009/12/atan2.jpg?w=280&h=283

 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();
}

}

最佳答案

public function moveToFood(food:Food):void
{
var speed:Number = 6.5;

var a:Number = food.x - x;
var b:Number = food.y - y;
var ang:Number = Math.atan2(b, a);

rotation = ang * 180 / Math.PI;

x += Math.cos(ang) * speed;
y += Math.sin(ang) * speed;
}

你不能只使用 sincos 向你面对的方向移动吗?

关于flash - Adobe Flash cs4 旋转数学,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6529348/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com