Godot Version
4.2.2
Question
this is the code for the player
extends CharacterBody2D
const SPEED = 10000.0
@onready var sprite = $AnimatedSprite2D
var direction = "forward"
func _physics_process(delta):
var direction_x = Input.get_axis("left", "right")
if direction_x:
velocity.x = direction_x * SPEED * delta
if(direction_x > 0):
direction = "right"
else:
direction = "left"
else:
velocity.x = move_toward(velocity.normalized().x, 0, SPEED)
var direction_y = Input.get_axis("up", "down")
if direction_y:
velocity.y = direction_y * SPEED * delta
if(direction_y > 0):
direction = "forward"
else:
direction = "backward"
else:
velocity.y = move_toward(velocity.normalized().y, 0, SPEED)
move_and_slide()
animations()
func _input(event):
if(event.is_action_pressed("attack")):
sprite.animation = "attack_" + direction
func animations():
if(!str(sprite.animation).begins_with("attack")):
if velocity != Vector2.ZERO:
sprite.animation = "run_" + direction
else:
sprite.animation = "idle_" + direction
func _on_animated_sprite_2d_animation_finished():
if(str(sprite.animation).begins_with("attack")):
sprite.animation = "idle_" + direction
after attacking, all the animations get stuck at the second frame