Godot 4 gdscript works delayed with simple character control template
In Godot, I coded movement codes for the platform game in gdscript, but it detects jumping etc. late, what could be the reason for this?
extends CharacterBody2D
const SPEED = 200.0
const JUMP_VELOCITY = -300.0
var gravity = ProjectSettings.get_setting("physics/2d/default_gravity")
@onready var animator = get_node("AnimationPlayer")
func _physics_process(delta):
if not is_on_floor():
velocity.y += gravity * delta
if Input.is_action_just_pressed("zipla") and is_on_floor():
velocity.y = JUMP_VELOCITY
animator.play("Jump")
var direction = Input.get_axis("sol", "sag")
if direction == -1:
get_node("AnimatedSprite2D").flip_h=true
elif direction == 1:
get_node("AnimatedSprite2D").flip_h=false
if direction:
velocity.x = direction * SPEED
if velocity.y == 0:
animator.play("Run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
animator.play("Idle")
if velocity.y>0:
animator.play("Fall")
move_and_slide()