the idle animation wont work

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By rgregre
extends KinematicBody2D

var acceliration = 200
var friction = 300
var speed = 60
var velocity = Vector2.ZERO
var gravity = 100
enum state {run,shoot,idle,jump,fall}
var player_state = state.idle
var can_jump = true
var move_direction

func _physics_process(delta):
	velocity = move_and_slide(velocity,Vector2.UP)

func _process(_delta):

func _unhandled_input(event):
	if event.is_action_pressed("jump") and can_jump:
		velocity.y = -50
func get_move_direction():
	move_direction = Input.get_action_strength("right") - Input.get_action_strength("left")
	$body.scale.x = move_direction

func move_aside(_delta):
	if move_direction !=0:
		velocity.x = move_toward(velocity.x,move_direction*speed,_delta*acceliration)
		player_state =
		velocity.x = move_toward(velocity.x,0,_delta*friction)
		player_state = state.idle

func apply_gravity(_delta):
	velocity.y += 100*_delta

func update_animation():

func check_floor():
	if is_on_floor():
		can_jump = true
		if velocity.y <0:
			player_state = state.jump
			player_state = state.fall
		can_jump = false
:bust_in_silhouette: Reply From: BigTuna675

Try converting your state keys to a string in the update animation function

func update_animation():

And make sure that the animation’s names match the state keys, but I’m guessing you already checked that.

You might also need to put the updateAnimation() call after the velocity = moveandslide() call because it seems like velocity is impacting the player’s state.

thanks for the reply ,

I already checked what you’ve mentioned , it still doesn’t work
however after checking the tree while the game is running, I can see that in the animatedSprite the idle animation is running but it wont show the sprite or the frames on the screen

rgregre | 2022-08-04 17:23

Untitled folder – Google Drive

i just shared the project

rgregre | 2022-08-04 17:34

Maybe you can try using an animation player instead of an animated sprite; the animation player node might be better suited to handle player animations. I think the use case scenario for the animated sprite node is a bit more niche, but I don’t remember where I learned that.

BigTuna675 | 2022-08-04 18:07

i’ve fixed it , i still don’t know how or why it didn’t work but , I made the “move” and “get direction” functions in one single function then i changed the player state according to the velocity where in the other code i used to change it when ever i change direction

rgregre | 2022-08-04 20:45