I've been trying to put in a double jump feature but it won't work, can anyone figure out why?

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Snazza

var jump_count = 0
const MAX_JUMP_COUNT = 2

if is_attacking == false:
if is_on_floor():
jump_count = 0
if jump_count < MAX_JUMP_COUNT and Input.is_action_just_pressed(“jump”):
motion.y = -JUMPFORCE
jump_count += 1
motion.y = -JUMPFORCE

Which part exactly isn’t working? Also, could you post your code with the proper formatting? I can’t tell what the indentation is, so I suspect the problem has to do with the second

motion.y = -JUMPFORCE

as it currently looks like you add the jump impulse regardless of whether or not the preceding if block is run.

CardboardComputers | 2021-08-31 13:52

:bust_in_silhouette: Reply From: Gluon

You could try going about it the other way around for example

var Total_Jumps: int = 2
if Total_Jumps > 0 and Input.is_action_just_pressed("jump"):
Total_Jumps -= 1
velocity.y = JUMPFORCE

if is_on_floor():
Total_Jumps = 2

I cannot figure out indentation on this forum sorry so you need to indent that correctly but I think that should work?

You type the code you want, indenting with 4 spaces where necessary, then highlight all of it and press the “Code Sample” { } button (or control+k) .

var Total_Jumps: int = 2
if Total_Jumps > 0 and Input.is_action_just_pressed("jump"):
    Total_Jumps -= 1
    velocity.y = JUMPFORCE

if is_on_floor():
    Total_Jumps = 2

timothybrentwood | 2021-08-31 22:37