good day,
I recently started using the Godot engine.
I'm in the process of making a character controller.
If you press the jump button it sometimes jumps and sometimes it doesn't.
maybe someone can help me with this problem.
Here is the code:
extends KinematicBody2D
const GRAVITY = 400
const SPEED = 100
const JUMP_POWER = 225
const UP_VECTOR = Vector2(0, - 1)
var movement = Vector2()
func _ready():
pass
func _process(delta):
movement.x = 0
if is_on_ceiling() or is_on_floor():
movement.y = 0
if is_on_floor():
movement.y = 0
movement.y += GRAVITY * delta
check_key_input()
move_and_slide(movement, UP_VECTOR)
set_animation()
func check_key_input():
if Input.is_action_pressed("left"):
movement.x = - 1 * SPEED
if Input.is_action_pressed("right"):
movement.x = 1 * SPEED
if Input.is_action_just_pressed("jump") and is_on_floor():
movement.y = -JUMP_POWER
func set_animation():
if movement.x < 0:
$Mario_Animation.flip_h = true
if movement.x > 0:
$Mario_Animation.flip_h = false