GDScript Not Working when running the game

Hey , I’m just starting godot but I ran into a problem . I made a Character and gave it the basic template of CharacterBody2D GDScript . So it should fall off the game when i run it . But it doesn’t . I think the script is not running . Even the character doesn’t move or jump . Can anyone help me pls

did you modified the template script or it’s just a fresh script from template?

ok, can you show the scene tree where you attached the script to the characterbody2d?

No I Didn’t . It’s completely fresh . Here’s the code :

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0

func _physics_process(delta: float) → void:

Add the gravity.

if not is_on_floor():
velocity += get_gravity() * delta

# Handle jump.
if Input.is_action_just_pressed("ui_accept") and is_on_floor():
	velocity.y = JUMP_VELOCITY

# Get the input direction and handle the movement/deceleration.
# As good practice, you should replace UI actions with custom gameplay actions.
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)

move_and_slide()

no i mean screenshot of the characterbody2d has the script attached

I have a node2d renamed root and a CharacterBody2D node renamed as player

here’s the player one

the characterbody2d is falling for sure but your camera2d just follow the player falling or moving, hence you see nothing changes

oh ! :sweat_smile: :sweat_smile: thank you very much . I attached it with the player so i didn’t noticed

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