首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >Adobe Flash cs4旋转数学

Adobe Flash cs4旋转数学
EN

Stack Overflow用户
提问于 2011-06-30 10:24:11
回答 1查看 652关注 0票数 3

我目前在旋转我的对象面对另一个object.currently时遇到了问题它工作得很好就像在这张图片中,我的对象在原点将能够旋转并移动到除正90度到180度的象限之外的3个象限中的对象,我的对象将在移动到对象的同时旋转几个完整的旋转一段时间,有人知道为什么吗?我用来旋转的句子是rotation += (foodLocationDegrees - (rotation - 90)) * .2;,用来计算食物

代码语言:javascript
运行
复制
var angle:Number = Math.atan2(foodTarget.y - y, foodTarget.x - x); 
            foodLocationDegrees =Math.floor((angle  * 180 / Math.PI));

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

代码语言:javascript
运行
复制
 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();
            }

        }
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-06-30 10:53:34

代码语言:javascript
运行
复制
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来朝你面对的方向移动吗?

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/6529348

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档