Scratch
Advanced
45 mins
Teacher/Student led
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:

    when green flag clicked set rotation style [left-right v] // this is important for when we make it move left and right later go to x [0] y [140] // place it at the top center at the start go to [front v] layer // 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.

    when green flag clicked set rotation style [left-right v] go to x [0] y [140] go to [front v] layer // add the new code under here set [gravity v] to (0) forever if < not < touching (ground v) ?> > then change y by (gravity) change [gravity v] by (-1) end end


    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:

    when green flag clicked forever if < < key (space v) pressed? > and < touching (ground v) ? > > then set [gravity v] to (10) // make them go up change y by (10) // move it so it's not touching the ground end end


    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