Character Animation / Movement problems

Godot 4.2.2

I keep getting this error
while trying to make animations for my FNAF game it didn’t happen before but now it does!

Invalid set index 'flip_h' (on base: 'null instance') with value type of 'bool'

Can somone help me please?

My code so far:

extends CharacterBody2D


const SPEED = 200
const FAST_SPEED = 400
var current_speed = SPEED
var animation_player : AnimationPlayer


const NORMAL_ANIMATION_SPEED = 1.0
const FAST_ANIMATION_SPEED = 2.0
var animation_speed = NORMAL_ANIMATION_SPEED

func _ready():
	var animation_player = $AnimationPlayer

func _physics_process(delta):

	var motion = Vector2.ZERO
	if Input.is_action_pressed("d"):
		$%prite.flip_h = false
		motion.x += 1
		$AnimationPlayer.play("Run")
	elif Input.is_action_pressed("a"):
		%Sprite.flip_h = true
		motion.x -= 1
		$AnimationPlayer.play("Run")
	elif Input.is_action_pressed("s"):
		motion.y += 1
		$AnimationPlayer.play("Run")
	elif Input.is_action_pressed("w"):
		motion.y -= 1
		$AnimationPlayer.play("Run")
	else:
		$AnimationPlayer.play("Idle")


	motion = motion.normalized()


	if Input.is_key_pressed(KEY_SHIFT):
		current_speed = FAST_SPEED
		animation_speed = FAST_ANIMATION_SPEED
	else:
		current_speed = SPEED
		animation_speed = NORMAL_ANIMATION_SPEED


	position += motion * current_speed * delta

Is it this line? try %Sprite

Yes it is @gertkeno but it still gives the same error

Is “Sprite” a child node in your scene with “unique name” (the % by it in the scene tree) enabled? Could you share a screenshot of this scene’s scene tree?

Capture

1 Like

I think you mean to use %Run instead of %Sprite. You could also use $Run, it doesn’t have to be a unique name if it is a direct child.

Oh! My bad

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