Topic was automatically imported from the old Question2Answer platform.
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.
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