Hey could someone help me undertand why my player wont move?

Godot Version

Godot Engine v4.2.stable.arch_linux

Question

I’ve been trying to make a basic pong game but nothing is moving, and I’m not getting nay errors
extends CharacterBody2D


var speed = 400

func _physics_process(delta):
	var velocity  = Vector2.ZERO
	if Input.is_action_pressed("ui_up"):
		velocity.y -= 1 
	if Input.is_action_pressed("ui_down"):
		velocity.y += 1 
	velocity *= speed
	move_and_slide()

I just found the solution! The problem is that godot4 is finicky with move_and_slide(), so you should use move_and_collide instead()!

extends CharacterBody2D

var speed = 400

func _physics_process(delta):
	var velocity  = Vector2.ZERO
	if Input.is_action_pressed("ui_up"):
		velocity.y -= 1 
	if Input.is_action_pressed("ui_down"):
		velocity.y += 1 
	velocity *= speed
	move_and_collide(velocity)

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.