Discuss Scratch
- Discussion Forums
- » Connecting to the Physical World
- » Gravity Explained
- DanDanbingobam
-
Scratcher
27 posts
Gravity Explained
Hi everyone! I’ve noticed a lot of people struggle with “choppy” movement when making platformers. After experimenting with different methods, I wanted to share the logic I use for smooth, realistic gravity.
The Problem with “Change Y by -10”
Most beginners just use a loop that changes Y by a fixed amount. This looks “floaty” because, in real life, gravity is acceleration—you start slow and get faster as you fall!
The Solution: The Y-Velocity Method
To get that smooth feel, you need a variable. Let's call it y_velocity.
The Logic:
Gravity: Every frame, decrease your y_velocity (e.g., change y_velocity by -1).
Movement: Every frame, move the player by that velocity (change y by y_velocity).
Collision: If you touch the ground, reset the velocity (set y_velocity to 0).
The Code Example
Code snippet
when green flag clicked
set to
forever
change by (-1) // The strength of gravity
change y by (y_velocity)
if <touching ?> then
repeat until <not <touching ?>>
change y by (1) // Push the player out of the floor
end
set to
end
end
The Problem with “Change Y by -10”
Most beginners just use a loop that changes Y by a fixed amount. This looks “floaty” because, in real life, gravity is acceleration—you start slow and get faster as you fall!
The Solution: The Y-Velocity Method
To get that smooth feel, you need a variable. Let's call it y_velocity.
The Logic:
Gravity: Every frame, decrease your y_velocity (e.g., change y_velocity by -1).
Movement: Every frame, move the player by that velocity (change y by y_velocity).
Collision: If you touch the ground, reset the velocity (set y_velocity to 0).
The Code Example
Code snippet
when green flag clicked
set to
forever
change by (-1) // The strength of gravity
change y by (y_velocity)
if <touching ?> then
repeat until <not <touching ?>>
change y by (1) // Push the player out of the floor
end
set to
end
end
- cheddargirl
-
Scratch Team
1000+ posts
Gravity Explained
Hey, so I noticed there's quite a few thread topics from you that were guide-like and not quite relevant to the discussion board section you were posting in.
While we know that users like to create topics that are guides, the discussion board space isn't really a good place for those types of things since they don't really invite for further discussion. Perhaps instead of making a forum thread guide, better to make a project instead?
While we know that users like to create topics that are guides, the discussion board space isn't really a good place for those types of things since they don't really invite for further discussion. Perhaps instead of making a forum thread guide, better to make a project instead?

- Discussion Forums
- » Connecting to the Physical World
-
» Gravity Explained