PDA

View Full Version : Aircraft Physics



Russkie
August 19th, 2003, 12:25 PM
I want to make an arrow, turn left or to the right while it is flying...

like that game called astroides...

when you turn left you will start to move in that direction...

can someone give the actionscript example?
I tryed to make this but the soo called aircraft dosen't move in the direction I turn , it just moves in the same direction I orginally assigned it to do.

Eric Jr.
August 19th, 2003, 02:48 PM
I made this a while ago for a contest, hope it helps:



Stage = { width: Stage.width, height: Stage.height };
c = [ [0,15,0,0],[5,0,-5,0] ];

_root.createEmptyMovieClip("fighter", 1).beginFill(0, 100);
for(i=0; i<c[0].length; i++) fighter.lineTo( c[0][i], c[1][i] );

fighter.onEnterFrameEvent = function()
{
newX = Math.cos( (currentAngle*(Math.PI/180)) );
newY = Math.sin( (currentAngle*(Math.PI/180)) );

if (Key.isDown(Key.LEFT) ) currentAngle -= 8;
if (Key.isDown(Key.RIGHT)) currentAngle += 8;
if (Key.isDown(Key.UP) && (mySpeed < 10)) mySpeed += 0.5;
if (Key.isDown(Key.DOWN) && (mySpeed > 0)) mySpeed -= 0.8;
if (this._x >= Stage.width) this._x = 1;
if (this._x <= 0 ) this._x = Stage.width;
if (this._y >= Stage.height) this._y = 1;
if (this._y <= 0 ) this._y = Stage.height;
if (mySpeed > 0) mySpeed -= 0.2;
if (mySpeed < 0) mySpeed = 0;

this._rotation = currentAngle;
this._x += newX * mySpeed;
this._y += newY * mySpeed;

updateAfterEvent();
}

fighter.interval = setInterval(fighter, "onEnterFrameEvent", 10);
fighter._x = Stage.width/2;
fighter._y = Stage.height/2;

Russkie
August 19th, 2003, 04:54 PM
could you give me the entire movie?
I don't know where to add this?

Eric Jr.
August 19th, 2003, 08:07 PM
That is the entire movie :bad:

Just copy all the code inside the onEnterFrameEvent function, and put that inside your objects onEnterFrame-event!