So I have the following code:
class ShipBehavior extends Sup.Behavior {
//Connect the ship to it's collision
ship_hull = this.actor.arcadeBody2D;
//Set the handling speed
speed : number = .025
awake() {
}
update() {
let x : number = this.actor.getX();
let x_speed : number = Math.abs(this.ship_hull.getVelocityX());
let new_x_speed : number = 0;
//Check in any key is pressed, and if one is, update the direction accordingly
//Handle leftward movement
if(Sup.Input.isKeyDown("A")){
new_x_speed =-this.speed;
}
//Handle rightward movement
else if(Sup.Input.isKeyDown("D")){
new_x_speed = this.speed;
}
this.ship_hull.setVelocityX(new_x_speed);
}
}
Sup.registerBehavior(ShipBehavior);
But it produces strange behavoir when run, as I move at a crawl to the left, but at a very fast (maybe 10x?) pace when I go left. this is literally the only script in the game, so the problem is going to be in here.
Thanks in advance,
Unwary