基于旋转在 X Y 轴上移动

Moving on X Y axis based on rotation

我试图让角色根据他们的旋转角度移动,但它移动起来就像是向右扫射。

import flash.events.KeyboardEvent;
import flash.events.MouseEvent;

lilman.rotation = 0
var personRotation:Number = lilman.rotation * (Math.PI / 180)

stage.addEventListener(KeyboardEvent.KEY_DOWN, function(e:KeyboardEvent)
{
    if(e.keyCode==65)
    {
        lilman.rotation -= 5
    }
    else if(e.keyCode==68)
    {
        lilman.rotation += 5
    }
})

stage.addEventListener(MouseEvent.MOUSE_DOWN, function()
{
    personRotation = lilman.rotation * (Math.PI / 180)

    lilman.x += Math.cos(personRotation)*5
    lilman.y += Math.sin(personRotation)*5

    trace(Math.cos(personRotation) +", "+ Math.sin(personRotation) +", "+ personRotation +", "+ lilman.rotation)
})

我已经测试了你的代码。 100% 没问题。

要解决扫射问题,您需要编辑 MovieClip 对象自身的旋转。
假设您的 MC 面朝上(北),使其面朝右(东)作为原点 0 度。

1) 右键单击​​ MC 并选择 编辑

2) 在编辑模式下...Select 所有内容,并且 (a) 将其向右旋转 90 度,(b) 将(之前的)底部与点 + 对齐。测试它是否按预期工作