Discuss Scratch

creator_tt4
Scratcher
11 posts

help with gravity

i dont know how to fix my gravity
https://scratch.mit.edu/projects/1110521047/
CHEEZ_ITZ_12oz
Scratcher
100+ posts

help with gravity

The main problem you have is that you are changing your position by “-1 * y-velocity”
What this is doing is that you move downwards just as fast as you jump upwards. Increasing your upwards velocity increases how fast you fall as well.
I would recommend having a hardcoded value for falling; or, for what I assume you're trying to go for, allow the y velocity to go negative on its own – when not touching the ground, constantly subtract from the y velocity; then use this value to directly change ypos. Actions like jumping would then alter the velocity, which then affects the y pos as a result.

Also, please clean up your codespace. If you right-click the background and select “Clean up Blocks” It will help you out a lot, trust me.
CarnoChaser6183
Scratcher
10 posts

help with gravity

Yea, Cheese is right. I have a simple gravity script here that you could try to work with. https://scratch.mit.edu/projects/924592745/
CarnoChaser6183
Scratcher
10 posts

help with gravity

Good grief. How do you end the bold typeface?
CHEEZ_ITZ_12oz
Scratcher
100+ posts

help with gravity

I guess if you want a direct fix, here is something you can do. In the block where you have “switch costume to falling”, replace the repeat block with this:
repeat (5)
change [yvel v] by (-3)
change y by (yvel)
end

Also, while we are in the same script, something to note about ( ) contains ( ). This block outputs true if the object on the right side is found in the left. For example (apple) contains (a). I mention this because of this block:
<[jump] contains (costume [name v])?>
While this still works as the name of the costume is jump itself, this generally isn't good ethics for programming. (neither is having a messy codespace)

As for @CarnoChaser6183, bold typeface is ended with {/b}, just with proper brackets ] and [

Powered by DjangoBB