My script isn't working it keeps saying

Godot 4
Line 10:Unexpected “Identifier” in class body. can somebody help

extends Node2D

const SPEED = 60

var direction = 1

@onready var ray_cast_down: RayCast2D = $RayCastDown
@onready var ray_cast_right: RayCast2D = $RayCastRight
@onready var ray_cast_left: RayCast2D = $RayCastLeft
@onready var animated_sprite: AnimatedSprite2D = $AnimatedSprite2D

export var gravity: float = 200  # Gravity strength

# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta):
	if ray_cast_right.is_colliding():
		direction = -1
		animated_sprite.flip_h = true
	if ray_cast_left.is_colliding():
		direction = 1
		animated_sprite.flip_h = false
	
	position.x += direction * SPEED * delta

var velocity: Vector2 = Vector2.ZERO

func _physics_process(delta): 
    # Check for ground below
		if not $RayCastDown.is_colliding():
			velocity.y += gravity * delta  # Apply downward force

		velocity = move_and_slide(velocity, Vector2.UP) 

This happens when you have a wrong character, please send a picture of the error so we can figure out exactly which column it is in.

Probably because of export, that was the keyword in Godot 3, but you’re using Godot 4 where it’s @export

3 Likes

I suppose it’s this line. Add @ before export and you should be fine.

1 Like