Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » how to do gravity?
- Oumuamua
-
1000+ posts
how to do gravity?
Don't worry >>> https://scratch.mit.edu/search/projects?q=gravity%20tutorial
- Gogy33567
-
8 posts
how to do gravity?
forever
end[scratchblocks]
bruh
[/scratchblocks]
Last edited by Gogy33567 (Nov. 19, 2022 07:06:00)
- Johan_Ha
-
12 posts
how to do gravity?
My approach to gravity is influenced by low level programming without fancy game engines. Scratch is kind of a high level game engine, but since it has no automatic gravity or acceleration, I would ditch the goto and glide commands. I'd create my own variables keeping track of coordinates and speeds.
The speed of an object can be defined as vx and vy, where vx is the “speed” in the horizontal dimension and vy in the vertical dimension. In Scratch, one could implement this by not using move steps or glide to, but using go to. Create new variables for the sprite coordinates.
Here's a simple gravity demo. I keep track of my own coordinates, x and y, as well as the speed in both directions, vx and vy. At each loop, I add a constant negative value to vy, which causes the acceleration downwards. At the bottom I just switch the sign of vy, which makes it bounce. Same with vx at the sides.
https://scratch.mit.edu/projects/764439570
The speed of an object can be defined as vx and vy, where vx is the “speed” in the horizontal dimension and vy in the vertical dimension. In Scratch, one could implement this by not using move steps or glide to, but using go to. Create new variables for the sprite coordinates.
Here's a simple gravity demo. I keep track of my own coordinates, x and y, as well as the speed in both directions, vx and vy. At each loop, I add a constant negative value to vy, which causes the acceleration downwards. At the bottom I just switch the sign of vy, which makes it bounce. Same with vx at the sides.
https://scratch.mit.edu/projects/764439570
- someone_random58
-
82 posts
how to do gravity?
For making a gravity jump, do this

when [space or up arrow v] key pressed
glide (A amount of seconds between 3 and 6) secs to x: (current x position) y: (y position)
wait (The amount of seconds how much it will take the time to glide) secs
glide (Between 3 or 6 seconds) secs to x: (current x position) y: (current y position)
- ztsereteli
-
91 posts
how to do gravity?
set [gravity] to [0]
repeat until <touching [Ground] ?>
change y by (gravity)
change [gravity] by (-1)
end
set [gravity] to [0]
- Discussion Forums
- » Help with Scripts
-
» how to do gravity?