Top down mouvement

Godot Version

4.2.2

Question

Hi everyone i made a top down movement controller based on this tutorial :

I get a weird bug when i put a camera node into my player node the camera with position smoothing enabled, the player can’t move, he go back to his starting position like a elastic, realy weird.

my code

extends CharacterBody2D

@export var mouvement_speed : float = 500
var character_direction : Vector2


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	character_direction.x = Input.get_axis("left", "right")
	character_direction.y = Input.get_axis("up", "down")
	character_direction = character_direction.normalized()
	
	if character_direction.x > 0: %sprite.flip_h = false
	if character_direction.x < 0: %sprite.flip_h = true
	
	
	if character_direction:
		velocity = character_direction * mouvement_speed 
		if %sprite.animation != "walking": %sprite.animation = "walking"
	else:
		velocity = velocity.move_toward(Vector2.ZERO, mouvement_speed)
		if %sprite.animation != "idle": %sprite.animation = "idle"

	move_and_slide()
		
	

do you have the player as a child of the camera on accident?

The player is moving, the camera is moving with the player. since you have no other objects in the scene, you have no frame of reference, so it looks like you are not moving.

That caught me out early on too. :smile:

Add a background to your scene, you’ll see the character IS moving. But set the Camera as a child of the player, so it will follow the player (and the camera smoothing to its final position is that “elastic” effect you see).
If you don’t want that, set the camera to be a child of the scene, not a child of the player.