Я создаю простую управляемую лодку в 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;
}
}
Заранее спасибо всем, кто может сказать мне, что я делаю неправильно.
EDIT:
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);
}
}
EDIT
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 );
}
}