The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes
extends KinematicBody2D

func _ready():

# physics
var speed : int = 500
var jumpForce : int = 600
var gravity : int = 800
var vel : Vector2 = Vector2()
var grounded : bool = false
# components
onready var sprite = $AnimatedSprite

func _physics_process (delta):
    # reset horizontal velocity
    vel.x = 0
    # movement inputs
    if Input.is_action_pressed("move_left"):
        vel.x -= speed
    elif Input.is_action_pressed("move_right"):
        vel.x += speed
        vel.x = 0
    # applying the velocity
    vel = move_and_slide(vel, Vector2.UP)
    # gravity
    vel.y += gravity * delta
    # jump input
    if Input.is_action_just_pressed("jump") and is_on_floor():
        vel.y -= jumpForce
    # sprite direction
    if vel.x < 0:
        sprite.flip_h = true
    elif vel.x > 0:
        sprite.flip_h = false
Godot version 3.4.4.stable
in Engine by (23 points)

1 Answer

0 votes

There are two problems here, the first is you have the check of the jump input after the move and slide has already completed and the second is that it is checking if left and right are in place before checking if the jump is happening.

Put the jump if in the same if block as the rest and make it the first check in that if block (make the move left check the first elif) this should fix it.

by (3,328 points)
Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.