How to Make Gravity in Scratch?

Create a variable named `y velocity`

Create a variable named `ground level`

Set `ground level` to the Y position where the sprite should stand

Set `y velocity` to `0` when the game starts

Use a `forever` loop

Add a small negative change to `y velocity` each frame to simulate gravity

Change the sprite’s `y` position by `y velocity`

If the sprite touches the ground level, set its `y` position to `ground level`

If the sprite touches the ground level, set `y velocity` to `0`

If the sprite can jump, set `y velocity` to a positive value when the jump key is pressed

If needed, use separate variables for `x velocity` and `y velocity`

If needed, add collision checks for platforms and walls

Suggested for You

Trending Today