Problems with project after Godot update

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

Well you reset it to false in _physics_process()

1 Like

Yes, but it shouldn’t be on the ground anymore. It only resets it if it is on the ground. I’ve tried changing the y position by 10 at the beginning of each jump too and that still doesn’t work.

How do you know it shouldn’t? When you set jumping to true and set the velocity to -500 in _input(), it doesn’t magically lift the character body off the ground. It’ll go off the ground only when move_and_slide() is first called after that, and that happens at the end of your _physics _process(). Before that call it’ll still be on the ground.

Put some breakpoints or print statements in your code to follow the execution flow and see the values of relevant variables.

1 Like

alright, I just moved the move and slide further up in the physics process. Thanks.

1 Like