My movement code not working can you fix it

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Fusegene Studios
extends CharacterBody2D

var speed = 200
var Velocity = Vector2()

func _physics_process(delta):

func handle_Input():
	Velocity = Vector2(
	if Input.is_action_pressed("up"):
		Velocity.y -= 1
	if Input.is_action_pressed("down"):
		Velocity.y += 1

Edited to fix code formatting

jgodfrey | 2023-03-11 21:21

You don’t say what’s wrong. Are you getting an error? Does it not do what you want? What do you want?

If the code you pasted is accurate, there’s a definite problem here:

Velocity = Vector2(

(notice the close paren is missing)

That said, you already have a global Velocity definition. I’d guess you might not even want/need the local definition.

jgodfrey | 2023-03-11 21:24

And, for Godot 4, move_and_slide() no longer takes a velocity argument as it’s now built in property of the node itself.

And, the property is named velocity, not Velocity

jgodfrey | 2023-03-11 21:27