Sprite not moving with camera top down. It looks like the sprite is stuck in place but the camera isnt. Sprite still responds to direction changes

Godot Version

v4.5

Question

Hey all, back on godot 4.2 this code worked. Basically I have a top down character that is a player_controller, has a collision shape, sprite, camera. When I do movement inputs the camera moves but the sprite stays in place. I’m not certain on what I can change. Here is the code and the tree.

extends CharacterBody2D

class_name Usr_top_down

const chara_name = "USR"
@export var movement : float = 100
@export var increaseMov: float = 30
@onready var collide = $CaydeColide
var spawn = Vector2i(0,0)
var direction : Vector2
var lastMovement: String
var run = false
var player1 = true

func _ready():
	collide.disabled = false
	
func _process(_delta) -> void:
	direction.x = Input.get_axis("ui_left", "ui_right")
	direction.y = Input.get_axis("ui_up", "ui_down")
	
	
	#if Input.is_action_just_pressed("light") and player1 == true:
			#player1 = false
			#$Sprites.animation = "ZaiIdleForward"
	#elif Input.is_action_just_pressed("light") and player1 == false:
		#player1 = true
		#$Sprites.animation = "IdleForward"
	if Input.is_action_just_pressed("Disable_collide"):
		if collide.disabled == false:
			collide.disabled = true
		elif collide.disabled:
			collide.disabled = false
		
	if direction:
		if Input.is_action_pressed("heavy") and run == false:
			movement = movement + increaseMov
			$Sprites.speed_scale += 0.5
			run = true
		elif Input.is_action_just_released("heavy") and run == true:
			movement = movement - increaseMov
			$Sprites.speed_scale -= 0.5
			run = false
		velocity = direction * movement
		#print(movement)
		if player1:
			if direction.x > 0: 
				$Sprites.animation = "RobotWalkRight"
				lastMovement = "RobotWalkRight"
			elif direction.x < 0: 
				$Sprites.animation = "RobotWalkLeft"
				lastMovement = "RobotWalkLeft"
			elif direction.y > 0: 
				$Sprites.animation = "RobotWalkForward"
				lastMovement = "RobotWalkForward"
			elif direction.y < 0: 
				$Sprites.animation = "RobotWalkbackwards"
				lastMovement = "RobotWalkbackwards"
		#else:
			#if direction.x > 0: 
				#$Sprites.animation = "ZaiWalkRight"
				#lastMovement = "ZaiWalkRight"
			#elif direction.x < 0: 
				#$Sprites.animation = "ZaiWalkLeft"
				#lastMovement = "ZaiWalkLeft"
			#elif direction.y > 0: 
				#$Sprites.animation = "ZaiWalkForward"
				#lastMovement = "ZaiWalkForward"
			#elif direction.y < 0: 
				#$Sprites.animation = "ZaiWalkBack"
				#lastMovement = "ZaiWalkBack"
	else:
		velocity = velocity.move_toward(Vector2.ZERO, movement)
		if player1:
			if lastMovement == "RobotWalkRight" : $Sprites.animation = "RobotIdleRight"
			elif lastMovement == "RobotWalkLeft" : $Sprites.animation = "RobotIdleLeft"
			elif lastMovement == "RobotWalkForward" : $Sprites.animation = "RobotIdleForward"
			elif lastMovement == "RobotWalkbackwards" : $Sprites.animation = "RobotIdleBackwards"
		#else:
			#if lastMovement == "ZaiWalkRight" : $Sprites.animation = "ZaiIdleRight"
			#elif lastMovement == "ZaiWalkLeft" : $Sprites.animation = "ZaiIdleLeft"
			#elif lastMovement == "ZaiWalkForward" : $Sprites.animation = "ZaiIdleForward"
			#elif lastMovement == "ZaiWalkBack" : $Sprites.animation = "ZaiIdleBack"
	move_and_slide()


func _on_timer_timeout():
	collide.disabled = false 

I’m assuming that the camera is a child of the player? In that case, the camera will move only if the player moves. Can you show the actual hierarchy of your player scene, not just the nodes themselves?

Yeah here you go

Hey,

I think you’re missing your reference to the sprites node as I only see an @onready for your collisionshape. If you’re not getting animations try getting that line back in there.

I don’t think you can reference nodes without doing that. So replace your movement code $sprites to sprites, and create a new @onready var sprites = $Sprites

Hey,

I think you’re missing your reference to the sprites node as I only see an @onready for your collisionshape. If you’re not getting animations try getting that line back in there.

I don’t think you can reference nodes without doing that. So replace your movement code $sprites to sprites, and create a new @onready var sprites = $Sprite

-edit -

I’d also try unchecking top level on your sprite, that can sometimes lead to unintended results.

It was toplevel that was the issue so thank you but I now have a follow up question. I basically have a dungeon spawner that spawns tiles for me and after all the tiles are spawned, the character is spawned. I have tried maaking it so the character z order is higher and other methods but my character is always under the sprites. This wasn’t ann issue back in 4.2 and I know tilemaps are different now but I can’t figure out what i need to change to fix it

If you’re z indexing where you player is a higher lYer than the tiles, maybe you also have top level selected for your tiles too. Did you check for that I’m the tile scene or their script?

If not what are you z indexs

Here is my dungeon Hierarchy. The UsrOverworld sprite is at zindex 10 while I made all children of OtherTileMap (what the tiles are attached to ignore the naming) 0. But despite them all being 0 it appears overtop of anyways. Any suggestions.

And they’re not set to top level? If not, what’s your code look like

I figured it out. I had thought I was setting top level but I wasn’t. Now that I did its workign