Topic was automatically imported from the old Question2Answer platform.
Asked By
ManiCus
I create gravity with this: vel.y += grav * delta and it works perfectly, but when I try to jump with: if is_on_floor():
if Input.is_action_just_pressed(“ui_up”):
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.is_action_pressed(“ui_left”): mov.x -= vel
if Input.is_action_pressed(“ui_right”): mov.x += vel
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
Hello
I was having the same problem and this fixed it. Thank you so much!!!