Skip to content

Instantly share code, notes, and snippets.

@anuraghazra
Created May 16, 2019 12:17
Show Gist options
  • Save anuraghazra/e3191a338c9a4f46f67d030e840072d0 to your computer and use it in GitHub Desktop.
Save anuraghazra/e3191a338c9a4f46f67d030e840072d0 to your computer and use it in GitHub Desktop.
update() {
let vel = Vector.sub(this.pos, this.oldpos);
vel.mult(this.friction);
// if the point touches the ground set groundFriction
if (this.pos.y >= CANVAS_HEIGHT - this.radius && vel.magSq() > 0.000001) {
var m = vel.mag();
vel.x /= m;
vel.y /= m;
vel.mult(m * this.groundFriction);
}
this.oldpos.setXY(this.pos.x, this.pos.y);
this.pos.add(vel);
this.pos.add(this.gravity);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment