Discuss Scratch

XXXXSandstormXXXX
Scratcher
26 posts

How do you make gravity using code?

Does anyone know how u make gravity, because I want to make a platformer, but I don't get how u do it, and I watched a YouTube tutorial, but the person was talking really fast, and I didn't know half of what he was saying….
Thx!
- XXXXSandstormXXXX

Last edited by XXXXSandstormXXXX (June 26, 2022 14:37:20)

scratch___user12345
Scratcher
1000+ posts

How do you make gravity using code?

can you share the project?
XXXXSandstormXXXX
Scratcher
26 posts

How do you make gravity using code?


scratch___user12345 wrote:

can you share the project?
wow…
RT_Borg
Scratcher
1000+ posts

How do you make gravity using code?

XXXXSandstormXXXX wrote:

wow…

Hi XXXXSandstormXXXX,

scratch___user12345 is a regular in the Help forum, and assists many scratchers. They are trying to help you by asking if you can share a project where you have either tried to implement gravity (but it isn't working right) or else a platformer you're working on that you'd like to add gravity in.

If you aren't started with the project yet, you might try asking if anyone has a very simple platformer with gravity you can look at, or knows of a really good tutorial. (Sorry, I haven't done a platformer yet, or I would help.)

– RT_Borg
XXXXSandstormXXXX
Scratcher
26 posts

How do you make gravity using code?

RT_Borg wrote:

XXXXSandstormXXXX wrote:

wow…

Hi XXXXSandstormXXXX,

scratch___user12345 is a regular in the Help forum, and assists many scratchers. They are trying to help you by asking if you can share a project where you have either tried to implement gravity (but it isn't working right) or else a platformer you're working on that you'd like to add gravity in.

If you aren't started with the project yet, you might try asking if anyone has a very simple platformer with gravity you can look at, or knows of a really good tutorial. (Sorry, I haven't done a platformer yet, or I would help.)
TYSM 4 ur advice!
scratch___user12345
Scratcher
1000+ posts

How do you make gravity using code?

I made a example project showing jumping and gravity. It has a “Y speed” variable that holds the value that the y is changed by every frame. then every time it moves it checks if it is touching the level, if so it undo's the action. then it checks if it had to undo the action, and if the “Y speed” was less than 0. if these both are true that means the player just hit the ground after falling, and then the program knows that the user can jump again. this is to prevent the user from jumping while in mid-air.
BarryFans
Scratcher
26 posts

How do you make gravity using code?

This is self explanatory. Use this script:
when green flag clicked
set [gravity v] to [0]
forever
change y by (gravity)
change [gravity v] by (-1)
end
XXXXSandstormXXXX
Scratcher
26 posts

How do you make gravity using code?

BarryFans wrote:

This is self explanatory. Use this script:
when green flag clicked
set [gravity v] to [0]
forever
change y by (gravity)
change [gravity v] by (-1)
end
TYSM!!! That works :)
BarryFans
Scratcher
26 posts

How do you make gravity using code?

XXXXSandstormXXXX wrote:

BarryFans wrote:

This is self explanatory. Use this script:
when green flag clicked
set [gravity v] to [0]
forever
change y by (gravity)
change [gravity v] by (-1)
end
TYSM!!! That works :)
No problem!
XXXXSandstormXXXX
Scratcher
26 posts

How do you make gravity using code?

BarryFans wrote:

XXXXSandstormXXXX wrote:

BarryFans wrote:

This is self explanatory. Use this script:
when green flag clicked
set [gravity v] to [0]
forever
change y by (gravity)
change [gravity v] by (-1)
end
TYSM!!! That works :)
No problem!
imma go follow u

Powered by DjangoBB