Discuss Scratch

Ausername57
Scratcher
100+ posts

infinite jumps

anyone know how to fix my games jumping? i want to make a double jump and i dont want it to jump infinite amounts of times. does anyone know how to fix this?

game: https://scratch.mit.edu/projects/1128791351/
Orange_Proto
Scratcher
25 posts

infinite jumps

if <[Jumps] < [2]> then
change [Jumps v] by (1)
Jump
end

This may work, I already tested the code in a project.
Catscratcher07
Scratcher
1000+ posts

infinite jumps

Make a variable keeping track of the number of jumps the player has and set it to 2 whenever they touch the ground. Whenever they press the jump button, first check that the variable is greater than zero, and only if it is do your jumping script and subtract one from the variable. You will also need to program a delay after the player jumps in which they can't jump again, otherwise the player would have to press jump for just a single frame to avoid wasting their double jump.
Ausername57
Scratcher
100+ posts

infinite jumps

Catscratcher07 wrote:

Make a variable keeping track of the number of jumps the player has and set it to 2 whenever they touch the ground. Whenever they press the jump button, first check that the variable is greater than zero, and only if it is do your jumping script and subtract one from the variable. You will also need to program a delay after the player jumps in which they can't jump again, otherwise the player would have to press jump for just a single frame to avoid wasting their double jump.
dosent work, can you give me the code for it?
Catscratcher07
Scratcher
1000+ posts

infinite jumps

Ausername57 wrote:

Catscratcher07 wrote:

Make a variable keeping track of the number of jumps the player has and set it to 2 whenever they touch the ground. Whenever they press the jump button, first check that the variable is greater than zero, and only if it is do your jumping script and subtract one from the variable. You will also need to program a delay after the player jumps in which they can't jump again, otherwise the player would have to press jump for just a single frame to avoid wasting their double jump.
dosent work, can you give me the code for it?
Jump should be in the forever loop with the other movement handling custom blocks, and should not have forever or any waits. (NEVER put forever or waits in a “run without screen refresh” custom block") Before setting y speed, run this if:
if <<(jump tracker) > [0]> and <[last jump] > [x]>> then //you can name last jump whatever you want, and x is a number to be determined by trial and error

end
after set y speed, set last jump to 0, at some other point in you game loop, change it by one.

Changing jump tracker by one should be done in your floor detection if.

Powered by DjangoBB