I have created a little rocket flying around a la metroid (from Shiffmans examples).
My problem is when rotating and thrusting the ship, it seems to continue do so until maxspeed is reached, or another rotation direction is added. I want the ship to stop turning and thrusting when I release the arrow keys.
In the update(), there is an acceleration.mult(0), that should stop any more acceleration. What am I missing?
Best,
David
Ship ship;
void setup() {
size(299, 299);
background(255);
smooth();
ship = new Ship(50,50);
}
void draw() {
background(255);
noStroke();
fill(0);
ship.keyPressed();
ship.update();
ship.display();
}
/////////////////////////
class Ship {
PVector location;
PVector velocity;
PVector acceleration;
float resistance;
float angle;
float heading;
// float r = 15;
// float theta = 0;
// float x = r * cos(theta);
// float y = r * sin(theta);
Ship(float _x, float _y) {
location= new PVector(_x, _y);
velocity= new PVector(0, 0);
acceleration= new PVector(0, 0);
heading = 0;
}
void update() {
//Deployment
velocity.add(acceleration);
velocity.limit(3);
location.add(velocity);
checkEdges();
//Incrementing/resetting before next frame
acceleration.mult(0);
}
void turn(String direction) {
if (direction=="right") {
heading+=0.05;
}
else if (direction=="left") {
heading-=0.05;
}
else if (direction=="straight") {
heading-=0;
}
}
void thrust() {
float angle = heading-PI/2;
PVector force = new PVector(cos(angle), sin(angle));