For some reason the code I took from a tutorial isnt working?

Godot Version

4.4

Question

ok so this is the code

extends CharacterBody2D

const speed = 50
const jump = -100
const gravity = 3
const acc = 1
# acc = acceleration

const UP = Vector2(0, -1)

var motion = Vector2()


func _physics_process(delta):
	motion.y += gravity
	
	if Input.is_action_pressed("move_right"):
		motion.x = speed
	elif Input.is_action_pressed("move_left"):
		motion.x = max(motion.x - acc, -speed)
	else:
		motion.x = lerp(motion.x, 0.0, 0.2)
		

Im trying to make my first game, a 2D platformer, and for some reason the game isnt working? The character doesnt move and the code doesnt give error. If I add a print(“left”) to the moving to the left it does print it so its working but the caracter isnt moving for some reason.

Someone help me, I have no idea TwT

It looks like you’re simply setting up a variable called “motion” and updating it based on the key presses. But you never hook up the motion to any sort of movement code, so you may as well call that variable

var some_variable_that_does_nothing = Vector2()

Your node is a CharacterBody2D, which means it is a special kind of Node2D. Every Node2D has a position variable that tells it where to draw itself on screen. I think you should try adding a line like

position += motion * delta at the end of _physics_process and see if that does what you want.

Oh that helps thankies :3