English 中文(简体)
轮换问题
原标题:rotation issues

很难使这一轮任降临。 i 有一个旋涡轮机,应当向另一个移动物体轮流。 它应当找到最短的轮换方向。

基本情况是,将行动描述从使用-1->, 179-180->, 359. 转换为行动文字,但现在,当目标在零度上跟踪时,就会出现问题。 轮机随后以其他方式轮换。

这里是法典。 我的心目是一小.。 它正在通过各物体之间的x差异,以及

public function Move(xdiff:Number,ydiff:Number){
        var currentRotation:Number;
        rot = Math.round(Math.atan(ydiff/xdiff) * (180/Math.PI));
        if(xdiff < 0){
            //this.rotation = 180 + rot;
            rot = rot + 180
        }else{
            //this.rotation = rot;
        }
        if(rot < 0 && rot > -90){
            rot = 270 + 90 + rot;
        }
        trace("idealrotation: " + rot + "currentrotation: " + rotation);
        currentRotation = rotation;
        if(currentRotation < 0){
            currentRotation += 360;
        }
        if(rot - currentRotation > 0){
            if(Math.abs(rot-currentRotation) < 5){
                rotation = rot;
            }else{
                rotation += rotationSpeed;
            }
        }else if(rot - currentRotation < 0){
            if(Math.abs(rot-currentRotation) < 5){
                rotation = rot;
            }else{
                rotation -= rotationSpeed;
            }
        }else{
            rotation = rot;
        }

        //this.rotation = rot;
    }
问题回答

Here is how I did it:

public function aim(stageX:Number, stageY:Number):void
{
    var angle:Number = (Math.atan2(stageY - y, stageX - x) - Math.PI * 0.5) * 180 / Math.PI;
    if (angle < 180) angle += 360;
    if (angle > 180) angle -= 360;
    targetAngle = angle;
}

x, y are coordinates of cannon, stageX, stageY - target.





相关问题
Attaching a property to an event in Flex/AS3

I have a parameter that needs to be passed along with an event. After unsuccessful attempts to place it on the type by extending the class, I ve been advised in another SO question to write a custom ...

Sorting twodimensional Array in AS3

So, i have a two-dimensional Array of ID s and vote count - voteArray[i][0] = ID, voteArray[i][1] = vote count I want the top 3 voted items to be displayed in different colors, so i have a 2nd Array -...

Virtual Tour using sketch up, ajax, flash technologies

I want to know if there are existing technology that make your 3d models in sketch into virtual tours, using either Ajax or Flash for web presentation. If there s none, which will be a good approach ...

What s a good way of deserializing data into mock objects?

I m writing a mock backend service for my flex application. Because I will likely need to add/edit/modify the mock data over time, I d prefer not to generate the data in code like this: var mockData =...

AS3 try/catch out of memory

I m loading a few huge images on my flex/as3 app, but I can t manage to catch the error when the flash player runs out of memory. Here is the what I was thinking might work (I use ???? because i dont ...

热门标签