我在Actionscript中創建了一個簡單的可控船隻,並且它已經得到了前進,左轉和右轉,但無法讓它轉向。我希望船沿它指向的方向前進。在ActionScript中的簡單船隻
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.x += speed;
player_mc.rotationZ += speed;
}
if(leftKeyIsDown)
{
player_mc.x -= speed;
player_mc.rotationZ -= speed;
}
if(upKeyIsDown)
{
player_mc.y -= speed;
}
}
在此先感謝任何能告訴我我做錯了什麼的人。
編輯:
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.rotationZ += turnFactor;
}
if(leftKeyIsDown)
{
player_mc.rotationZ -= turnFactor;
}
if(upKeyIsDown)
{
player_mc.x += speed * Math.cos(player_mc.rotationZ * Math.PI/180);
player_mc.y -= speed * Math.sin(player_mc.rotationZ * Math.PI/180);
}
}
編輯
function moveBoat(event:Event):void
{
if(rightKeyIsDown)
{
player_mc.rotation += turnFactor;
}
if(leftKeyIsDown)
{
player_mc.rotation -= turnFactor;
}
if(upKeyIsDown)
{
// convert our rotation to radians first
var rads:Number = player_mc.rotation * (Math.PI/180.0);
player_mc.x += speed * Math.cos(rads);
player_mc.y += speed * Math.sin(rads);
}
}
而不是'player_mc.y - = ...',設置'player_mc.y + = ...',它會工作。就像我在我的回答中提到的那樣... – divillysausages 2011-04-26 16:42:05