Discuss Scratch
- Discussion Forums
- » Help with Scripts
- » How do I make gravity for a platformer game?
- Picoguy
-
Scratcher
100+ posts
How do I make gravity for a platformer game?
Ive been looking for an answer to this for a while now. All the forum posts I can find are outdated and no longer work. Please Help!
- awesome-llama
-
Scratcher
1000+ posts
How do I make gravity for a platformer game?
It depends on how you want to do it. I am assuming that you are making your own platformer physics.
You would want to have the platformer store data in variables, including X velocity and Y velocity. These would be used every tick to change the X and Y positions.
As for gravity, all you need to do is change the Y velocity every tick due to the acceleration due to gravity. In real life, this is g=-9.8m/s, which means every tick in scratch being 1/30 of a second makes this change -9.8/30 m/s every tick.
You would want to have the acceleration from gravity to change the Y velocity into negative values. See my example script:
You would want to have the platformer store data in variables, including X velocity and Y velocity. These would be used every tick to change the X and Y positions.
As for gravity, all you need to do is change the Y velocity every tick due to the acceleration due to gravity. In real life, this is g=-9.8m/s, which means every tick in scratch being 1/30 of a second makes this change -9.8/30 m/s every tick.
You would want to have the acceleration from gravity to change the Y velocity into negative values. See my example script:
// do this every tick / game loop
change [Y velocity v] by (-1) // set this to whatever you want acceleration to be
change [Y position v] by (Y velocity)
Last edited by awesome-llama (Jan. 28, 2020 02:25:10)
- franceware
-
Scratcher
100+ posts
How do I make gravity for a platformer game?
the easiest way is to add this script
the best way to do it, can be found in this Wikipedia article, that's pretty much what awesome-llama says.
https://en.m.wikipedia.org/wiki/Gravity
when green flag clicked
forever
change y by (-5)
end
the best way to do it, can be found in this Wikipedia article, that's pretty much what awesome-llama says.
https://en.m.wikipedia.org/wiki/Gravity
- Starstriker3000
-
Scratcher
1000+ posts
How do I make gravity for a platformer game?
I made a platformer script tutorial a while ago. Maybe it'll help.
- Discussion Forums
- » Help with Scripts
-
» How do I make gravity for a platformer game?