Hello, I am tinkering with 2D platforming and have based my code off of Miziziziz's tutorials (one hour platformer and make a platformer in 10 minutes), but am trying to change the way he implemented short and full hopping. This is the code below:
func on_air_jump_timeout(): #Called when the player has pressed jump and
jumped_in_air = false
func on_jump_control_timeout():
jump_control = true
func _physics_process(delta):
if Input.is_action_pressed("escape"):
get_tree().quit()
var move_direction = Vector2()
if Input.is_action_pressed("left"):
move_direction.x += -1
if Input.is_action_pressed("right"):
move_direction.x += 1
velocity.x += (move_direction.x * MOVE_SPEED - DRAG * velocity.x)
if abs(velocity.x) >= 5:
clamp(velocity.x, -5, 5)
var grounded = is_on_floor()
var pressed_jump = Input.is_action_just_pressed("jump")
if grounded:
modified_jump = false
if grounded and pressed_jump:
velocity.y = -JUMP_FORCE
jump_control_timer.start()
if jump_control and !grounded and !modified_jump:
if Input.is_action_pressed("jump"):
velocity.y = -HIGH_JUMP
jump_control = false
modified_jump = true
if (Input.is_action_just_released("jump") or !Input.is_action_pressed("jump")):
velocity.y = -SHORT_HOP
jump_control = false
modified_jump = true
velocity.y += GRAVITY
if grounded and velocity.y >= 5:
velocity.y = 5
if velocity.y > MAX_FALL_SPEED:
velocity.y = MAX_FALL_SPEED
move_and_slide(velocity, Vector2.UP)
func flip(): #Flip changes the orientation of the player sprite and also changes a flag to track its state
facing_right = !facing_right
sprite.flip_h = !sprite.flip_h
The problem is that the player can only short hop once, and then is locked into full hops no matter how long the jump action is held. Any help you can provide would be appreciated.