Discuss Scratch
- ReadHowToMakeTheGame
-
11 posts
How to make a gravity script?
I need to make the game with jump but I don't know how to make it
- ReadHowToMakeTheGame
-
11 posts
How to make a gravity script?
Last edited by ReadHowToMakeTheGame (May 22, 2024 16:31:46)
- GvYoutube
-
1000+ posts
How to make a gravity script?
I need to make the game with jump but I don't know how to make it
Last edited by GvYoutube (May 22, 2024 16:26:17)
- born_2010
-
5 posts
How to make a gravity script?
I need to make the game with jump but I don't know how to make it
Although I'm not sure if this is what you need, this is how I usually create gravity scripts in Scratch:
First, I start with a variable called “y velocity,” and set it to 0 at the beginning.
After that, I make a forever loop, and inside it I place a ‘change y velocity by -1’ block.
Right below that block I place a ‘change y by y velocity’ block.
The script should look similar to this:
This is the core of the program, as without it you cannot have realistic gravity. After you make this, you may wish to add a component that makes the player collide with the ground when they land on it. If so y velocity should be set to 0 when they touch the ground so that they stop falling. Something else you might want to consider is jumping. If you want to make the player jump, you should probably just set y velocity to a positive number like 15 when they press the jump key. This will make them move up instead of down. If you want to make them fall faster or slower, change the “-1” in the script to something larger or smaller. Either way, there are multiple different things this script can be used for that involve gravity, so this should probably be useful no matter what you are working on.
I hope this helps!

- --CHA0S--
-
100+ posts
How to make a gravity script?
Then adding on to this, add into the script after the change y blockI need to make the game with jump but I don't know how to make it
Although I'm not sure if this is what you need, this is how I usually create gravity scripts in Scratch:
First, I start with a variable called “y velocity,” and set it to 0 at the beginning.
After that, I make a forever loop, and inside it I place a ‘change y velocity by -1’ block.
Right below that block I place a ‘change y by y velocity’ block.
The script should look similar to this:This is the core of the program, as without it you cannot have realistic gravity. After you make this, you may wish to add a component that makes the player collide with the ground when they land on it. If so y velocity should be set to 0 when they touch the ground so that they stop falling. Something else you might want to consider is jumping. If you want to make the player jump, you should probably just set y velocity to a positive number like 15 when they press the jump key. This will make them move up instead of down. If you want to make them fall faster or slower, change the “-1” in the script to something larger or smaller. Either way, there are multiple different things this script can be used for that involve gravity, so this should probably be useful no matter what you are working on.
I hope this helps!
This is the core of the collision if you need it

- Lightslayr1681
-
48 posts
How to make a gravity script?
For the jump, I recommend in the “if touching ground”, you put,
Since gravity is constantly pulling the player, this should work
Since gravity is constantly pulling the player, this should work
Last edited by Lightslayr1681 (May 22, 2024 21:16:56)
- ItBeJC
-
1000+ posts
How to make a gravity script?
Everybody here has given part of a fully functional jumping script, but not the full script.
(Currently editing this post to include scripts)
EDIT: Forgot to include ceiling collisions. Its included now.
Keep in mind these scripts can be optimized but they should work for your needs. Also make sure to tick “Run Without Screen Refresh” on the custom block or it will not work correctly.
(Currently editing this post to include scripts)
EDIT: Forgot to include ceiling collisions. Its included now.
Keep in mind these scripts can be optimized but they should work for your needs. Also make sure to tick “Run Without Screen Refresh” on the custom block or it will not work correctly.
Last edited by ItBeJC (May 23, 2024 19:58:03)
- tank401
-
100+ posts
How to make a gravity script?
For actual gravity you need a bunch of things, Gravity, velocity, and Y value
Gravity is set in stone and never changes.
Velocity goes down by the value of Gravity when you're not touching the ground.
Y values goes down by the value of velocity.
This should simulate acceleration, you need to do the touching things though.
Gravity is set in stone and never changes.
Velocity goes down by the value of Gravity when you're not touching the ground.
Y values goes down by the value of velocity.
This should simulate acceleration, you need to do the touching things though.
- Create-Scratch101
-
500+ posts
How to make a gravity script?
There is a good wiki article: Simulating Gravity
- ItBeJC
-
1000+ posts
How to make a gravity script?
Simulating GravityThat deals with gravity around a center point, not platformer gravity, which is what they're asking for. There is a good wiki article:
- tank401
-
100+ posts
How to make a gravity script?
Love how you come into a forum to say someone is wrong, ignoring the guy who wants help
- HogwartsTeacherSnape
-
100+ posts
How to make a gravity script?
Why are you asking for help if you literally just typed the code out?
- ItBeJC
-
1000+ posts
How to make a gravity script?
Love how you come into a forum to say someone is wrong, ignoring the guy who wants help
Everybody here has given part of a fully functional jumping script, but not the full script.
(Currently editing this post to include scripts)
EDIT: Forgot to include ceiling collisions. Its included now.
Keep in mind these scripts can be optimized but they should work for your needs. Also make sure to tick “Run Without Screen Refresh” on the custom block or it will not work correctly.
- maxc1ne
-
1 post
How to make a gravity script?
.
Last edited by maxc1ne (Feb. 6, 2025 18:04:19)
- codeisBOOM
-
100+ posts
How to make a gravity script?
I need to make the game with jump but I don't know how to make it