version 4
why does my animation pause on the first frame for a second and only then play the rest of the animation?
self explanatory. whenever the animation plays it pauses. if i go the the right, jump and turn only then does it actually work. if you can help me id be pretty jolly. i am very bad at coding. here is my code. help.
extends CharacterBody2D
@onready var animated_sprite = $AnimatedSprite2D
const SPEED = 300.0
const JUMP_VELOCITY = -400.0
# Movement
func _physics_process(delta):
# Gravity
if not is_on_floor():
velocity += get_gravity() * delta
# Jump
if Input.is_action_just_pressed("jump") and is_on_floor():
velocity.y = JUMP_VELOCITY
# Movement
var direction := Input.get_axis("left", "right")
if direction:
velocity.x = direction * SPEED
if Input.is_action_pressed("run"):
velocity.x *= 5
else:
velocity.x = move_toward(velocity.x, 0, SPEED)
move_and_slide()
# Animations
if not is_on_floor():
if velocity.y < 0:
animated_sprite.play("jump")
if velocity.x < -350.0:
animated_sprite.play ("jump run")
else:
animated_sprite.play("fall")
elif direction != 0:
animated_sprite.play("walk")
if velocity.x > 500:
animated_sprite.play("run speed 1")
if velocity.x < -500:
animated_sprite.play("run speed 1")
else:
animated_sprite.play("idle")
# Flip
if direction > 0:
animated_sprite.flip_h = false
elif direction < 0:
animated_sprite.flip_h = true