Gravity in javascript game | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Gravity in javascript game

Hello, Does anybody know how I can add gravity in my game by using handleMove?

10th Feb 2020, 6:44 AM
Betina
Betina - avatar
4 Answers
+ 3
//You can use JavaScript libraries for that //matter.js https://brm.io/matter-js/ //physics.js http://wellcaffeinated.net/PhysicsJS/ //without using libraries, reference code https://code.sololearn.com/We2wI3xFuT9b/?ref=app
10th Feb 2020, 7:04 AM
Sudarshan Rai
Sudarshan Rai - avatar
+ 2
you'll can add constant downforce for your entity for basic gravity. const downforce = 10; function jump(entity){ entity.down = downforce - 10; } and treat them as a acceleration, not velocity or exact Y location.
10th Feb 2020, 7:04 AM
Taste
Taste - avatar
+ 2
A yt vid to add gravity https://youtu.be/3b7FyIxWW94
10th Feb 2020, 5:12 PM
Farhan
Farhan - avatar
0
by using gravity u need to be precise more importantly on the programming language that your using each coding language has their effect depending the language your using try Html i believer it will be easier, for me i use html and javascript..................
19th Oct 2020, 11:22 PM
Israel o. Akintola
Israel o. Akintola - avatar