Godot Version
4.6.1
Question
This is a little snippet I use when making platformer projects, and it has usually worked until recently. Whenever I press space, the jumping variable only becomes true for one tick, and is instantly reset to false. Does anyone know how I can fix this, and what the cause of this is?
extends CharacterBody2D
var jumping = false
func _physics_process(delta: float) -> void:
if not is_on_floor():
velocity.y += 20
elif jumping == false:
velocity.y = 0
if is_on_floor() and jumping:
jumping = false
velocity.x = Input.get_axis("left","right") * 500
move_and_slide()
func _input(event: InputEvent) -> void:
if event.is_class("InputEventKey") and event.pressed:
if event.keycode == 32 and not jumping:
velocity.y = -500
jumping = true