Gravity
Section 13: The pro project: a jumping gameLesson 13.1 · ⏱ 9 min
In real games a character doesn't move at a fixed speed. We use a variable speed: at every moment the speed goes down by 1 (gravity pulls down), and the character moves by the speed. When it reaches the ground we stop it.



📌 Note
Predict: if speed started at 10 instead of 0, what would happen first? (He goes up a little, then falls.)
📌 Another example: a bouncing ball
When the ball reaches the ground we don't set the speed to zero; we flip it and multiply it by 0.7, so it bounces a little less each time until it settles.




✍️ Practise
Change the starting point to y = 50, then to y = 140. When does Robo reach the ground sooner?
✍️ Practise here in the lesson✖ Close the labor open the lab in a new page ↗
🎯 Challenge yourself
Easy
Moon gravity: make the gravity -0.5 instead of -1. Does Robo fall more slowly?
👀 Show the solution🙈 Hide the solution


Medium
Robo falls while moving to the right (change x by 4 inside forever), like a thrown ball.
👀 Show the solution🙈 Hide the solution


Hard
Trampoline: every time Robo touches the ground he shoots up at speed 15, and count the bounces in a variable bounces.
👀 Show the solution🙈 Hide the solution



