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.

asked Apr 12 in Engine by ManiCus (76 points)
edited Apr 12 by ManiCus

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 
answered Apr 12 by Atomic Potato (84 points)
selected Apr 12 by ManiCus
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 How to use this Q&A? before posting your first questions.