Godot Version
4.6.1
Question
I don’t know How to solve It
extends CharacterBody2D
var speed = 600
var last_dir = "down" # default direction
@onready var ani := $kob as AnimatedSprite2D
func get_input():
var dir = Input.get_vector("ui_left","ui_right","ui_up","ui_down")
velocity = dir * speed
func _physics_process(delta):
get_input()
move_and_slide()
update_animation()
func update_animation():
if velocity != Vector2.ZERO:
if abs(velocity.x) > abs(velocity.y):
if velocity.x > 0:
ani.play("walk_right")
last_dir = "right"
else:
ani.play("walk_left")
last_dir = "left"
else:
if velocity.y > 0:
ani.play("walk_down")
last_dir = "down"
else:
ani.play("walk_up")
last_dir = "up"
else:
ani.play("idle_" + last_dir)