DriversRecommendedOutdated drivers can make a good PC feel brokenScan driver issues before chasing fixes manually.Scan NowOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsWindows FixRecommendedWindows errors stealing your time? Find the fix fastScan stability, cleanup and performance issues.Fix Now×
Skip to content
VGSources
Blog

How to Add Gravity in Scratch: A Beginner’s Guide

Build natural-looking Scratch platformer gravity with a vertical-velocity variable, collision detection, jumping, and adjustable physics values.
WorldScratch: A Beginner's Guide Length6 min Posted Quest giverVGSources Team
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Scratch has no dedicated gravity block. The usual solution is to create a vertical-velocity variable: move the sprite by its current velocity, reduce that velocity each loop, and reset it when the sprite lands. A positive velocity moves up; a negative velocity moves down.

How gravity works in Scratch

Scratch uses a coordinate system in which increasing y moves a sprite upward and decreasing y moves it downward. Gravity is therefore a game simulation rather than a built-in physics feature. The sprite’s vertical velocity controls its movement, while gravity changes that velocity over time.

As an Amazon Associate I earn from qualifying purchases.

  • Positive velocity: the sprite moves upward.
  • Zero velocity: the sprite stops moving vertically.
  • Negative velocity: the sprite moves downward.

For example, a jump velocity of 12 might become 11, 10, and so on as gravity is applied. When it reaches 0, the sprite is at the jump’s peak. It then becomes -1, -2, and falls increasingly quickly.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

This velocity-based approach is the conventional way to create platformer gravity in Scratch; it is not a requirement imposed by Scratch itself. See the Scratch community discussion of gravity and velocity and the official block reference.

#1 Best Overall

Create the variables

Select the player sprite, click Variables, choose Make a Variable, and create these variables using For this sprite only:

  • y velocity — how far the sprite moves vertically each loop.
  • gravity — how much the velocity changes each loop.
  • jump power — the upward velocity given to a jump.

Making the variables local to the player prevents enemies or other sprites from accidentally sharing the player’s vertical motion. Scratch supports both global variables and variables that belong only to the selected sprite; its variable guide explains the distinction.

Start with basic falling

First, test gravity without platforms or jumping:

when green flag clicked
set [y velocity v] to (0)
forever
    change y by (y velocity)
    change [y velocity v] by (-1)
end

The sprite begins stationary, then its velocity becomes increasingly negative, so it falls faster. This script intentionally has no floor check, which means the sprite eventually falls off the Stage.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Add a floor collision

Make your ground a consistent color, or use a separate platform sprite. Then add a collision check after the sprite moves:

Rank #2
Sale
The Official Scratch Coding Cards (Scratch 3.0): Creative Coding Activities for Kids
  • Book: the official scratch coding cards (scratch 3.0): creative coding activities for kids
  • Language: english
  • Cards binding
when green flag clicked
set [y velocity v] to (0)
forever
    change y by (y velocity)
    change [y velocity v] by (-1)

    if <touching color [ground color] ?> then
        repeat until <not <touching color [ground color] ?>>
            change y by (1)
        end
        set [y velocity v] to (0)
    end
end

Use the color picker in the touching color block to select the exact color used by the platform. The official Scratch documentation describes how this sensing block works.

The repeat until loop is important. If the sprite has moved partly into the floor, it moves upward one unit at a time until it is no longer touching the ground. Setting the velocity to zero then prevents continued downward movement.

Add jumping

Initialize the tuning variables and put the jump check inside the grounded collision condition:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
when green flag clicked
go to x: (0) y: (100)
set [y velocity v] to (0)
set [gravity v] to (-1)
set [jump power v] to (12)

forever
    change y by (y velocity)
    change [y velocity v] by (gravity)

    if <touching color [ground color] ?> then
        repeat until <not <touching color [ground color] ?>>
            change y by (1)
        end

        set [y velocity v] to (0)

        if <key [space v] pressed?> then
            set [y velocity v] to (jump power)
        end
    end
end

Change the example starting coordinates to match your level. The order matters:

  1. Move by the velocity from the previous loop.
  2. Change the velocity using gravity.
  3. Check for a collision.
  4. Push the sprite out of the platform.
  5. Stop its downward velocity.
  6. Allow a jump only while it is grounded.

Gravity changes velocity; it does not directly move the sprite. The velocity is what changes the sprite’s y position.

Choose a platform-detection method

Touching a color

<touching color [ground color] ?>

This is convenient when the level is drawn in one sprite or backdrop. It is sensitive to exact colors, gradients, anti-aliased edges, decorative objects, and the visible shape of the player.

Touching a platform sprite

<touching [Platform v] ?>

This is often clearer when platforms are separate sprites. It can become harder to manage when a level contains many independent platform objects.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Use a collision mask

A dedicated sprite or color layer containing only solid surfaces keeps decoration from accidentally becoming part of the floor. This is a useful upgrade for larger levels.

Tune the jump

Setting Starting value Effect
gravity -1 Moderate downward acceleration
jump power 10–15 Normal platformer jump strength
Stronger gravity -2 Heavier, faster-falling movement
Weaker gravity -0.5 Floatier movement
Maximum fall speed -15 to -20 Prevents extremely fast falls

These are game-tuning values, not real-world measurements. Copying Earth’s 9.8 directly into Scratch is not meaningful unless you have defined a scale for pixels, time, and acceleration. Lower jump power or make gravity more negative for a shorter, heavier jump. Raise jump power or use less-negative gravity for a higher, floatier jump.

To limit falling speed, add this after applying gravity:

if <(y velocity) < (-18)> then
    set [y velocity v] to (-18)
end

Prevent repeated or accidental jumps

Never put an unrestricted jump check in the main loop:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
if <key [space v] pressed?> then
    set [y velocity v] to (12)
end

That permits air-jumps and can repeatedly reset the velocity while Space is held. The basic solution is to check the key only inside the ground-collision condition, as shown above.

Holding Space can still cause an immediate new jump when the sprite lands. For stricter control, track whether jumping is available:

if <touching color [ground color] ?> then
    set [can jump v] to (1)
else
    set [can jump v] to (0)
end

if <<key [space v] pressed?> and <(can jump) = (1)>> then
    set [y velocity v] to (jump power)
    set [can jump v] to (0)
end

For a polished game, key-press detection can be separated from the physics loop so one held key is treated as one jump rather than repeated input.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

Troubleshooting gravity and platforms

Problem Likely cause Fix
The sprite falls forever No collision check, or the wrong platform color Check after movement and reselect the exact ground color.
The sprite falls through the floor It moves farther in one loop than the platform’s thickness Cap the fall speed or use smaller, pixel-by-pixel movement.
The sprite is stuck in the floor Velocity is reset without removing overlap Use repeat until not touching and move upward by one unit.
The sprite jumps infinitely The jump key is checked while airborne Require a ground collision or a can jump variable.
The sprite never falls Velocity is repeatedly set to zero, or another script changes y Search for every script that changes y or y velocity.
The platform is not detected Wrong color, costume padding, or decorative artwork Use a collision mask or a separate platform sprite.
The sprite passes through a ceiling The floor-only correction always moves upward Use direction-sensitive correction for ceilings.
The jump feels too heavy or floaty Gravity and jump power are mismatched Tune both values together rather than copying real-world numbers.

A more reliable vertical collision upgrade

The simple floor script assumes that every collision is a landing. A more complete system checks the direction of travel:

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.
change y by (y velocity)

if <touching [Platform v] ?> then
    repeat until <not <touching [Platform v] ?>>
        if <(y velocity) < (0)> then
            change y by (1)
        else
            change y by (-1)
        end
    end
    set [y velocity v] to (0)
end

When falling, the sprite is pushed upward out of the platform. When rising into a ceiling, it is pushed downward. Setting velocity to zero stops both downward and upward motion after the collision.

For fast or complex games, separate horizontal and vertical collision handling, move in small increments, and handle floors, ceilings, and walls independently. One-way platforms additionally need logic that resolves collisions only while the player is falling. Slopes and moving platforms require further adjustments; the basic gravity loop does not automatically make a player follow either one.

Why not use glide or fixed jump loops?

glide moves a sprite over a chosen duration but does not expose the per-loop velocity needed for responsive gravity and collision handling. Similarly, a script such as “repeat 10 times, change y by 5” creates a predetermined jump rather than one controlled by acceleration, collisions, or momentum. Repeated change y by blocks driven by a velocity variable are a better foundation for a platformer. See the Scratch community guidance on platformer movement.

What to remember

A working beginner gravity system has four ideas:

  1. Store vertical movement in y velocity.
  2. Move by that velocity each loop.
  3. Change the velocity by gravity each loop.
  4. When the player lands, remove overlap, set velocity to zero, and allow a jump.

Start with gravity = -1 and jump power = 12, then adjust the numbers until the movement suits your level.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More quests from Patch Notes

  1. How to Set Up a RedM (RDR2) Server in 2026: License Key, txAdmin and server.cfg, Step by StepBlog11min
  2. Best RedM (RDR2) Server Hosting in 2026: Comparing Four Hosts on Slots, Memory and PriceBlog10min
  3. How to Host a Mindustry Server in 2026: server-release.jar, Port 6567 and the Commands That MatterBlog7min
Recommended PC Tool
Recommended PC Tool
PC Slower Than It Used to Be?Free scan - under a minute
Outdated Drivers Are Slowing You DownFree scan - exact matches

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.