Hi , I Wanted To add gravity and jumping mechanincs to my game and im kinda new to godot so i look some videos to give me an idea on how i could do it but my code doesnt work the gravity works properly but the jumping doesn't work this is my code
extends KinematicBody2D
var velocidad = Vector2(0,0)
export var speed = 300
export var velocity = 250
export var masa = 2
const gravedad = 10
export var salto = -100
const right = "ui_right"
const left = "ui_left"
const jump = "salto"
func _physics_process(delta):
position.y -= delta * velocity * -2
GetInput()
animations()
func GetInput():
velocidad = Vector2(0,0)
if Input.is_action_pressed(right):
velocidad.x += speed
elif Input.is_action_pressed(left):
velocidad.x -= speed
if Input.is_action_just_pressed(jump) and is_on_floor():
velocidad.y = salto
velocidad = move_and_slide(velocidad, Vector2(0,-1))
func animations():
if Input.is_action_pressed(right):
$AnimatedSprite.play("Walking")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed(left):
$AnimatedSprite.play("Walking")
$AnimatedSprite.flip_h = true
elif !Input.is_action_pressed(right) and !Input.is_action_pressed(left):
$AnimatedSprite.play("Idle")