AnimatonHelpWithError

Godot Version

2.4.1.stable

Question

I’m getting the error “invalid set index flip_h on base animation player with value of type bool.” with this code.

extends CharacterBody2D

@onready var animations = $AnimationPlayer
@export var speed: int = 100
var current_dir = "none"

func playerMovement(delta):
	if Input.is_action_pressed("ui_right"):
		current_dir = "right"
		playAnimations(1)
		velocity.x = speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_left"):
		current_dir = "left"
		playAnimations(1)
		velocity.x = -speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_down"):
		current_dir = "down"
		playAnimations(1)
		velocity.x = 0
		velocity.y = speed
	elif Input.is_action_pressed("ui_up"):
		current_dir = "up"
		playAnimations(1)
		velocity.x = 0
		velocity.y = -speed
	else:
		playAnimations(0)
		velocity.x = 0
		velocity.y = 0
	
func playAnimations(movement):
	var dir = current_dir
	
	if dir == "right":
		animations.flip_h = false
		if movement == 1:
			animations.play("walkRight")
		elif movement == 0:
			animations.play("idleRight")
			
	if dir == "left":
		animations.flip_h = true
		if movement == 1:
			animations.play("walkRight")
		elif movement == 0:
			animations.play("idleRight")
			
	if dir == "down":
		animations.flip_h = true
		if movement == 1:
			animations.play("walkDown")
		elif movement == 0:
			animations.play("idleDown")
			
	if dir == "up":
		animations.flip_h = true
		if movement == 1:
			animations.play("walkUp")
		elif movement == 0:
			animations.play("idleUp")
		
		
	
	
	
func _physics_process(delta):
	playerMovement(delta)
	move_and_slide()

How do i fix it.

$AnimationPlayer node doesnt have flip_h property, make sure you flip_h the right node

it said your $AnimationPlayer is AnimationPlayer Type node, make sure it’s AnimatedSprite type node

Okay, how would I do it in AnimationPlayer though.

what is your sprite node name? show your scene tree?

then change to:

extends CharacterBody2D

@onready var animations = $AnimationPlayer
@onready var sprite= $Sprite2D
@export var speed: int = 100
var current_dir = "none"

func playerMovement(delta):
	if Input.is_action_pressed("ui_right"):
		current_dir = "right"
		playAnimations(1)
		velocity.x = speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_left"):
		current_dir = "left"
		playAnimations(1)
		velocity.x = -speed
		velocity.y = 0
	elif Input.is_action_pressed("ui_down"):
		current_dir = "down"
		playAnimations(1)
		velocity.x = 0
		velocity.y = speed
	elif Input.is_action_pressed("ui_up"):
		current_dir = "up"
		playAnimations(1)
		velocity.x = 0
		velocity.y = -speed
	else:
		playAnimations(0)
		velocity.x = 0
		velocity.y = 0
	
func playAnimations(movement):
	var dir = current_dir
	
	if dir == "right":
		sprite.flip_h = false
		if movement == 1:
			animations.play("walkRight")
		elif movement == 0:
			animations.play("idleRight")
			
	if dir == "left":
		sprite.flip_h = true
		if movement == 1:
			animations.play("walkRight")
		elif movement == 0:
			animations.play("idleRight")
			
	if dir == "down":
		sprite.flip_h = true
		if movement == 1:
			animations.play("walkDown")
		elif movement == 0:
			animations.play("idleDown")
			
	if dir == "up":
		sprite.flip_h = true
		if movement == 1:
			animations.play("walkUp")
		elif movement == 0:
			animations.play("idleUp")
		
		
	
	
	
func _physics_process(delta):
	playerMovement(delta)
	move_and_slide()

Thank you so so much! :clap:

1 Like

Wait, now I can’t move diagonally.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.