- Edited
Hello,
I am trying to make a 2D platformer Character Controller, and there's two movement mechanics I have had a lot of trouble getting to work in unison: that being, variable jump height and double jumping. What I mean by variable jump height is that your jump height depends on how long you hold down the jump button. I guess my question is, why shouldn't this work?
var can_jump: bool = false
var can_double_jump: bool = false
var jump_timer: float = 0
var jump_force: float = 200
func jump(force):
> velocity.y = -force
func _physics_process(delta: float) -> void:
> if is_on_floor():
>> can_jump = true
>> can_double_jump = true
>
> if Input.is_action_just_pressed("jump"):
>> if can_jump && can_double_jump:
>>> can_jump = false
>> if can_jump == false && can_double_jump:
>>> can_double_jump = false
>
> if Input.is_action_pressed("jump") && jump_timer < 0.25 && (can_jump or can_double_jump):
>> jump(jump_force)
>> jump_timer += delta
>
>if Input.is_action_just_released("jump"):
>> jump_timer = 0
Thank you for your help, hopefully this code is readable. I am just getting into game dev and I'm excited to hear feedback!