Godot Version
Replace this line with your Godot version
I’ve recently started trying game dev and I’ve followed a couple tutorials, some on youtube and some on this forum, I was trying to implement a variable jump (like if you press short your jump is short) but I came across a glitch where if you spam the jump button, you slow fall, how can I fix this? here is the entirety of my code, again, if some of the code is unnecessary, I would love some feedback as I literally started coding last week
const SPEED = 130.0
const JUMP_VELOCITY = -260.0
@onready var animated_sprite_2d: AnimatedSprite2D = $AnimatedSprite2D
var can_jump = true
@onready var coyote_timer: Timer = $CoyoteTimer
#function for jumps AKA that one thing that makes you jump
func jump():
velocity.y = JUMP_VELOCITY
can_jump = false
func _physics_process(delta: float) -> void:
# Add the gravity.
if not is_on_floor():
velocity += get_gravity() * delta
#restores your jumps when on the ground
else:
can_jump = true
if (is_on_floor() == false) and can_jump == true and $CoyoteTimer.is_stopped():
$CoyoteTimer.start()
# Handles the jump
if can_jump == true:
if Input.is_action_just_pressed("Jump"):
jump()
else:
if Input.is_action_just_released("Jump") or is_on_ceiling():
velocity.y *= 0.5
#this is the player movement code
var direction := Input.get_axis("Walk_left", "Walk_rigth")
if direction:
velocity.x = direction * SPEED
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
# This code handles the sprite direction and animation playing
if direction > 0:
animated_sprite_2d.flip_h = false
elif direction < 0:
animated_sprite_2d.flip_h = true
if is_on_floor():
if direction == 0:
animated_sprite_2d.play("Idle")
else:
animated_sprite_2d.play("Walk")
else:
animated_sprite_2d.play("Jump")
func _on_coyote_timer_timeout() -> void:
can_jump = false
type or paste code here
type or paste code here