For further actions, you may consider blocking this person and/or reporting abuse
Read next
How to create a typewriter effect text animation with Tailwind CSS and JavaScript
Michael Andreuzza -
LZ4 โย C++ React Native bindings for an extremely fast compression algorithm
Mateo Guzmรกn -
Navbar & Footer By Bootstrap5
Mahmud R. Farhan -
The React `useInsertionEffect` Hook
Alfredo Salzillo -
Top comments (2)
How did you manage the gravity?
I really like how it looks!
Howdy!
There are three types of gravity:
1) Normal one. For that, you need to create a speed variable and then a indipendent speed for both X and Y of the character which you can manipulate by pressing the buttons (so, pressing D will add speed to the X variable, A will reduce that and so on). On the update loop you have, you need to have a gravity and friction variables. Friction: will gradually stop your character from moving (you need to do something like player.friction = 0.8; speedX *= player.friction; ) and the same with gravity (player.gravity = 0.3; speedY -= player.gravity; ). You can learn more here: somethinghitme.com/2013/01/09/crea... ;
2) When you press X, you reduce the gravity to 0 and put a boolean for stopping the speedY to decrease over time, so you can move freely in a top-down fashion (after mapping the W and S buttons to do that like you did for A and D). When you press X again, you return to your normal gravity and change again the boolean (I did something like maxGravity, so you can remember the initial gravity what it was);
3) For adding the gravity effects, I did a maxGravity and gravity editing every time you enter to a door, so it could be 0.035 one time and 0.002 later, or maybe 0.07 or simply 0 or -0.035.
Hope it helps :)