Discuss Scratch

blackspider222
Scratcher
50 posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

This is a very reasonable script to make a sprite only jump when touching ground and i dont know why it doesnt work. So here it is :

variable
(in air?)

when green flag clicked
forever
if <touching [platform v] ?>then
set [(in air? v] to [no]

else

set [(in air? v] to [yes]

end

if <[in air?] = [no]> then
if <key [up arrow v] pressed?> then
set [gravity v] to [15]

end
end
end


DOESNT WORK
scratch___user12345
Scratcher
1000+ posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

can you share the project
blackspider222
Scratcher
50 posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

scratch___user12345 wrote:

can you share the project


Here it is: https://scratch.mit.edu/projects/678033542/editor/
Kiska-7275
Scratcher
1000+ posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

With the gravity set block, also use
change y by (10)

Last edited by Kiska-7275 (April 21, 2022 11:53:34)

blackspider222
Scratcher
50 posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

Kiska-7275 wrote:

With the gravity set block, also use
change y by (10)


Wait set gravity to 15 is the same tho

Last edited by blackspider222 (April 21, 2022 11:55:02)

Kiska-7275
Scratcher
1000+ posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

blackspider222 wrote:

Kiska-7275 wrote:

With the gravity set block, also use
change y by (10)


Wait set gravity to 15 is the same tho
It is for gravity to work
ggenije2
Scratcher
100+ posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

It doesn't work because the “Gravity” custom blocks moves you up until you don't touch the ground and then when you check collision after that are you above air it will always be “yes”.
So remove your check collision part , and instead set the “in air” to either yes or no at the gravity custom block.

Last edited by ggenije2 (April 21, 2022 11:56:10)

blackspider222
Scratcher
50 posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

ggenije2 wrote:

It doesn't work because the “Gravity” custom blocks moves you up until you don't touch the ground and then when you check collision after that are you above air it will always be “yes”.
So remove your check collision part , and instead set the “in air” to either yes or no at the gravity custom block.


Wdym? Show me the code.

And i removed the
if <> then 



else

end


block and in the gravity custom block i added the ‘in air’ code.
blackspider222
Scratcher
50 posts

HELP! This script to make my sprite jump only when touching ground DOESNT WORK! :( -platformer-

DISCUSSION CLOSED, THANKS GUYS FOR THE INFO, THE BUG IS GONE SO PLEASE DONT POST ANYMORE

Powered by DjangoBB