0 votes

I create gravity with this: vel.y += grav * delta and it works perfectly, but when I try to jump with: if isonfloor():
if Input.isactionjustpressed("uiup"):
mov.y -= vel_jump
it dosent work when the player is standing in a static body.

PD: "mov" is working beacause i use this for X moves:
if Input.isactionpressed("uileft"):
mov.x -= vel
if Input.is
actionpressed("uiright"):
mov.x += vel

and it perfectly works.

in Engine by (108 points)
edited by

1 Answer

+1 vote
Best answer

I'm assuming that you are making a 2D game and using a Kinematic Body node as player, if that is the case then here is an example of how I implement jump mechanics I hope it helps :)

var VELOCITY = Vector2()
var SPEED = 400
var GRAVITY = 550
var JUMP_FORCE = 500

func _physics_process(delta):
    VELOCITY.y += GRAVITY * delta
    get_input()
    VELOCITY = move_and_slide(VELOCITY, Vector2(0, -1))


func get_input():
    VELOCITY.x = 0

    if Input.is_action_pressed("ui_right"):
        VELOCITY.x += SPEED 
    if Input.is_action_pressed("ui_left"):
        VELOCITY.x -= SPEED 
    if is_on_floor() and Input.is_action_just_pressed("ui_up"):
        VELOCITY.y -= JUMP_FORCE 
by (84 points)
selected by

Hello

I was having the same problem and this fixed it. Thank you so much!!!!! :)

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.