I say "deceleration" because I'm not using acceleration at the moment; what I mean is moving the velocity back towards zero, eventually stopping.
I'm new to vectors and not so great with physics and such. How is "deceleration" normally handled?
What I have now works, but it seems kind of hackish.
update:function(Game, t, dt) {
var speed = Game.Input.isKeyDown('shift') ? 8 : 4;
if (Game.Input.isKeyDown('a')) {
this.velocity.i -= speed;
}
else if (Game.Input.isKeyDown('d')) {
this.velocity.i += speed;
}
else {
if (Math.abs(this.velocity.i) > 3) {
this.velocity.i += (this.velocity.i > 0) ? -speed : speed;
}
else {
this.velocity.i = 0;
}
}
if (Game.Input.isKeyDown('w')) {
this.velocity.j -= speed;
}
else if (Game.Input.isKeyDown('s')) {
this.velocity.j += speed;
}
else {
if (Math.abs(this.velocity.j) > 3) {
this.velocity.j += (this.velocity.j > 0) ? -speed : speed;
}
else {
this.velocity.j = 0;
}
}
this.updateVectors(dt);
}
I used 3 because anything lower exhibits weird behaviour, I'm guessing if I raised the speed then it would need to be changed.
velocity.i += speed;
thespeed
is in fact your acceleration, i.e. the rate that velocity changes by. :) \$\endgroup\$