Skip to content

Instantly share code, notes, and snippets.

@HilmiZul
Last active September 29, 2018 20:08
Show Gist options
  • Save HilmiZul/be86244668ebca57924edc0c038a656e to your computer and use it in GitHub Desktop.
Save HilmiZul/be86244668ebca57924edc0c038a656e to your computer and use it in GitHub Desktop.
catatan kecil simulasi benda (seolah) jatuh.
/* grav.js
* 30 September 2018, 3:00 A.M.
*/
function grav() {
this.g = 0.9; // gravitasi
this.vel = 0; // init 0 yang nanti ditambah dengan nilai gravitasi saat benda jatoh.
// saat benda jatoh:
// kecapatan benda akan terus bertambah dengan tarikan gravitasi?
// posisi benda ditambah dengan kecepatan yang terus bertambah selama benda-
// belum sampe tanah...
this.fall = function() {
this.vel += this.g;
this.posBenda += this.vel;
};
// cek, apakah benda udah jatoh ke tanah?
this.check = function() {
if (this.posBenda > this.heightBenda - (this.r / 2)) {
this.posBenda = this.heightBenda - (this.r / 2));
}
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment