Root animation player aint workin

Godot Version 4.2

so i am pretty much trying to make a single frame show up whenever i start to go downwards in this racing game im making, only problem is it aint letting me
i genuinely have no idea why. the error says “Node not found: “/root/PlayerCar/AnimationPlayer” (absolute path attempted from “/root/PlayerCar”).” and i have no idea what its talkin about.
here’s the simple movemonet script i got goin:
extends CharacterBody2D
var speed = 1000
var maxspeed = 1000
var friction = 1500
var input = Vector2.ZERO
func _physics_process(delta):
player_movement(delta)
func get_input():
input.x = int(Input.is_action_pressed(“right”)) - int(Input.is_action_pressed(“left”))
input.y = int(Input.is_action_pressed(“backward”)) - int(Input.is_action_pressed(“forward”))
return input.normalized()

func player_movement(delta):
input = get_input()

if input == Vector2.ZERO:
	if velocity.length() > (friction * delta):
		velocity -= velocity.normalized() * (friction * delta)
	else:
			velocity = Vector2.ZERO
else:
	velocity += (input * speed * delta)
	velocity = velocity.limit_length(maxspeed)
if velocity.y > 0:
	$/root/PlayerCar/AnimationPlayer.play("DOWN")
move_and_slide()

func _on_slowbox_body_entered(_body):
maxspeed = 400
speed = 300
friction = 800
func _on_slowbox_body_exited(_body):
maxspeed = 1000
speed = 1000
friction = 1500
and the scene tree looks like this
image
someone pls help i got nothing

Since the AnimationPlayer is a child of PlayerCar, you should just be able to change

$/root/PlayerCar/AnimationPlayer.play("DOWN")

to

$AnimationPlayer.play("DOWN")

If you did want to reference it using from the root then you need the full path. Since PlayerCar is under MAP not directly under root here, it should be

$/root/MAP/PlayerCar/AnimationPlayer.play("DOWN")

It seems to work using the full code, so thank you for helping!!! :smiley:

1 Like