Godot Version
4.2
Question
I’m currently trying to make a player animation system where whenever you aren’t moving it plays a looping idle animation, and whenever you start moving in a direction it triggers a one shot animation corresponding to whichever direction you are going. however currently, it either plays the idle animation until you start moving then plays only the first frame of each corresponding movement animations untill you stop moving which lets the direction animation play, OR it only plays the first frame of each corrisponding movement animation. i have been following this tutorial: https://www.youtube.com/watch?v=Luf2Kr5s3BM&t=2417s
and this is my code:
extends CharacterBody2D
#controll player speed in the editor
@export var move_speed : float
#find animation tree
@onready var animation_tree = $AnimationTree
@onready var state_machine = animation_tree.get("parameters/playback")
#movement code
func _ready():
pass
func _physics_process(_delta): #physics
#get input direction
var input_direction = Vector2(
Input.get_action_strength("right") - Input.get_action_strength("left"),
Input.get_action_strength("down") - Input.get_action_strength("up"),
)
update_animation_parameters(input_direction)
#update velocity to new direction
velocity = input_direction.normalized()* move_speed
#makes player move
move_and_slide()
pick_new_state(input_direction)
#syncs animation with movement
func update_animation_parameters(move_input : Vector2):
if(move_input != Vector2.ZERO):
animation_tree.set("parameters/Move/blend_position", move_input)
#when not moving make animation idle
func pick_new_state(move_input : Vector2):
if(velocity != Vector2.ZERO):
state_machine.travel("Move")