if Input.is_action_pressed("move_left"):
animated_sprite_2d.play("side")
animated_sprite_2d.flip_h = true
direction = Vector2.LEFT
elif Input.is_action_pressed("move_right"):
animated_sprite_2d.play("side")
animated_sprite_2d.flip_h = false
direction = Vector2.RIGHT
elif Input.is_action_pressed("backward"):
animated_sprite_2d.play("back")
animated_sprite_2d.flip_h = false
direction = Vector2.UP
elif Input.is_action_pressed("forward"):
animated_sprite_2d.play("front")
animated_sprite_2d.flip_h = false
direction = Vector2.DOWN
This is code to run the character animation but it has thrown up a new error when I try to run it throws "attempt to call function ‘play’ in base null instance on a null instance "
Please could you help me with this too. Thank you so much
We need to know your scene is structured because you’re getting a null instance, to help you get the correct value we need to know how your nodes are organized.
In this case you just need to do equal the video u send: @onready var animated_sprite_2d = $AnimatedSprite2D. You forget the “$” before the AnimatedSprite2D
You should find info about NODE PATH on Youtube.
If you use @onready var animated_sprite_2d = %AnimatedSprite2D, then your NODE in scene tree, must be “Access by unique name”, “%” - sign that trigger Godot to find node by unique name.
If NODE does not use unique name, then you should use “$” before your node name. Thats the point - you need PATH to node.