Scratch
45 mins
What you need:
Chromebook/Laptop/PC or iPad/Tablet

Scratch Gravity and Jumping

This lessons teaches you how to make a character jump and have gravity pull them back down to the ground in Scratch.

Lesson Files

Live Class Feed

This is a live feed of the latest activity by your students on this lesson. It will update in real-time as they work on the lesson.
Load previous activity

    1 - Create a new Scratch project

    Create a new Scratch project and delete the cat sprite.

    2 - Add the Dinosaur4 sprite from the library.

    Change it's size to 50% in the Sprite properties and then add the following code to the dino sprite:

    whenclickedsetrotationstyleleft-right this is important for when we make it move left and right latergotox0y140 place it at the top center at the startgotofrontlayer make it appear over the ground sprite


    3 - Draw the 'ground' sprite

    Use the sprite editor to draw a 'ground' sprite. Use the Rectangle tool to draw a green box and drag it so it covers the bottom half of the stage area.

    Rename this sprite to 'ground' in the sprite properties.


    4 - Create a 'gravity' variable and make the dino fall

    Create a variable called 'gravity' and then add the below code. This code makes the dino fall if it's not touching the ground.

    whenclickedsetrotationstyleleft-rightgotox0y140gotofrontlayer add the new code under heresetgravityto0foreverifnottouchingground?thenchangeybygravitychangegravityby-1


    5 - Make the dino jump

    We're going to program the space bar key to make the dino jump but the dino should only be able to jump if it's touching the ground (you can't jump in mid-air!!).

    Add the following code to the dino:

    whenclickedforeverifkeyspacepressed?andtouchingground?thensetgravityto10 make them go upchangeyby10 move it so it's not touching the ground


    Unlock the Full Learning Experience

    Get ready to embark on an incredible learning journey! Get access to this lesson and hundreds more in our Digital Skills Curriculum.

    Copyright Notice
    This lesson is copyright of Coding Ireland. Unauthorised use, copying or distribution is not allowed.

    Scratch is developed by the Lifelong Kindergarten Group at the MIT Media Lab. It is available for free at https://scratch.mit.edu
    🍪 Our website uses cookies to make your browsing experience better. By using our website you agree to our use of cookies. Learn more