Hello! I started to develop a 2D platform game. I just bumped into a strange issue: when I press 'W' input key for jump, the jump is delayed by about 0.5 seconds.
This is the player controller:
extends KinematicBody2D
const UP = Vector2(0, -1)
const GRAVITY = 20
const SPEED = 200
const JUMP_HEIGHT = -500
var motion = Vector2()
func _physics_process(delta):
motion.y += GRAVITY
if Input.is_action_pressed("ui_right"):
motion.x = SPEED
elif Input.is_action_pressed("ui_left"):
motion.x = -SPEED
else:
motion.x = 0
if is_on_floor():
if Input.is_action_just_released("ui_up"):
motion.y = JUMP_HEIGHT
motion = move_and_slide(motion, UP)
I use the following tutorial for developing the game:
I checked this issue in the Google, and I found out this post:
https://stackoverflow.com/questions/67778261/godot-jump-animation-starting-after-a-slight-delay-from-the-input
Here are several solutions, but the one that caught my attention is this:
Is on floor?
The value is_on_floor() is updated when you call move_and_slide(...). But you are calling is_on_floor() before calling move_and_slide(...), which means it is operating the value of the prior physics frame. In fact, you want move_and_slide(...) to hit the ground (and thus, you probably want to apply gravity first).
This by it self is not a big deal. It is mostly noticeable for frame perfect jump, but still.
I tried this solution: I changed places the 'is_on_floor()' loop and 'motion = move_and_slide...' statement, but nothing has changed.
How could I get rid of this issue?