Skip to content

Instantly share code, notes, and snippets.

@patricoferris
Created August 10, 2018 22:12
Show Gist options
  • Save patricoferris/a8f38187051d31f5fe46037a9b7994b1 to your computer and use it in GitHub Desktop.
Save patricoferris/a8f38187051d31f5fe46037a9b7994b1 to your computer and use it in GitHub Desktop.
class Satellite extends Planet {
constructor(position, mass, radius, color, vel) {
//Telling Planet to build a base planet for us
super(position, mass, radius, color);
//Redefining the velocity to be something we pass it (shadowing)
this.velocity = vel;
//Our new variable acceleration
this.acceleration = createVector(0, 0);
}
//An apply force function - check the physics section to understand this
applyForce(force) {
var f = p5.Vector.div(force, this.mass);
this.acceleration.add(f);
}
//And an update function
update() {
this.velocity.add(this.acceleration)
this.position.add(this.velocity);
this.acceleration.mult(0);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment