Hello people, I encountered the problem of delaying animations in Godot 4, it either works crookedly or does not work at all. I wrote the code at first myself, then I watched several videos on YouTube, rewrote the code as it was there, and it still didn’t help.
extends CharacterBody2D
const SPEED = 300.0
const JUMP_VELOCITY = -500.0
var lop = true
var gravity = ProjectSettings.get_setting(“physics/2d/default_gravity”)
@onready var an = $a
func _physics_process(delta):
# Add the gravity.
if not is_on_floor():
velocity.y += gravity * delta
# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
velocity.y = JUMP_VELOCITY
an.play("jump")
var lop = false
# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction = Input.get_axis("ui_left", "ui_right")
if direction:
velocity.x = direction * SPEED
if velocity.y ==0:
an.play("run")
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
if velocity.y == 0:
an.play("idlle")
if direction == -1:
$a.flip_h = true
if direction == 1:
$a.flip_h = false
move_and_slide()