New developer and need help with my jump script for Godot 4.0 (2D)

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By CheetoPuffs

Whenever my player spawns, he falls through the map. Before this happened, my player would be able to jump but he would just go so high and wouldn’t be able to come down. I have looked at many tutorials but they either only work for Godot 3 or have many unnecessary lines of code that I can’t understand or are not needed

This is my script:

extends CharacterBody2D

const speed = 50
const gravity = 10
const jp = -300

func _ready(): # when the scene loads this happens right when it loads
pass # pass is telling it to ignore all the code

func _process(delta): #delta just means “frame”, this code will repeat every frame
pass

func _physics_process(delta): #better with maths than process delta
movement()

func movement(): #movement func.

velocity.y += gravity

if Input.is_action_pressed("ui_right"):
	velocity.x = speed
elif Input.is_action_pressed("ui_left"):
	velocity.x = -speed
if is_on_floor() and Input.is_action_just_pressed("ui_accept"):
	velocity.y = jp
if not is_on_floor():
	velocity.x = move_toward(velocity.x, 0, 5) # slowly reduce horizontal velocity to 0
		
		
		
move_and_slide()
:bust_in_silhouette: Reply From: CheetoPuffs

FIXED IT! I didn’t have collision on my tiles, lmao.