انتقل للمحتوى
Robo EgyptRobo Egypt
☰ Course contents
Robo Block: home
0. Lab tour1
1. Getting started5
2. Motion5
3. Looks and sound5
4. Events4
5. Loops5
6. Conditions and sensing4
7. Variables and randomness4
8. Project: the “Catch Robo” game3
9. Messages: characters talk to each other4
10. Clones: one character, many copies4
11. My Blocks: make a new block3
12. Operators and time4
13. The pro project: a jumping game4

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.

Blocks: when 🚩 clicked, go to x: (0) y: (150), set (speed) to (0), forever
Robo falls faster and faster
Robo falls faster and faster
Robo on the ground, and speed = 0
Robo on the ground, and speed = 0
📌 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.

Blocks: when 🚩 clicked, go to x: (0) y: (140), set (speed) to (0), forever
It falls
It falls
It bounces
It bounces
It settled
It settled
✍️ Practise
Change the starting point to y = 50, then to y = 140. When does Robo reach the ground sooner?
✍️ Practise here in the lessonor 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
Blocks: when 🚩 clicked, go to x: (0) y: (140), set (speed) to (0), forever
He reached the ground slowly
He reached the ground slowly
Medium

Robo falls while moving to the right (change x by 4 inside forever), like a thrown ball.

👀 Show the solution
Blocks: when 🚩 clicked, go to x: (-200) y: (140), set (speed) to (0), forever
He fell at a slant
He fell at a slant
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
Blocks: when 🚩 clicked, go to x: (0) y: (100), set (speed) to (0), set (bounces) to (0), forever
He bounces without stopping
He bounces without stopping
Finished the lesson? Mark it so your progress counts.