I’m trying to get a ship to move with a thruster and retain its velocity
here’s the code
package
{
import flash.display.Sprite;
public class Ship extends Sprite
{
;
var thrust:Number=0;
var xVel:Number=0;
var yVel:Number=0;
var xAcc:Number=0;
var yAcc:Number=0;
var gravity:Number=1;
var rVel:Number=0;
var lVel:Number=0;
public function Ship():void
{
}
public function moveShip():void
{
rotation = rVel;//rVel is controlled by left and right keyPress
var angle:Number=rotation*Math.PI/180;
trace("angle Is " + angle);
xAcc=Math.cos(angle) * thrust;
yAcc=Math.sin(angle) * thrust;
xVel+=xAcc;
yVel+=yAcc
x=xVel;
y=yVel;
trace(rVel);
trace("xVel="+ xVel)
trace("yVel="+ yVel)
trace("move ship");
trace("thrust= " + thrust);
}
the trace statements show a change in X velocity and that X velocity doesn’t return to 0
on the screen the ship will ONLY move like the thruster is mounted on the left side(pushing it right) and will not retain it’s velocity(it will only move each time i hit the thruster).
What am I doing wrong here?? It looks right to me.