My game keeps crashing please help

Godot Version 4.1.1

`
my game crashes when i try and run it
here

Question is the script

extends CharacterBody2D

const SPEED = 300.0
const JUMP_VELOCITY = -400.0
const GRAVITY = 980.0

@onready var animated_sprite = $AnimatedSprite2D

func _physics_process(delta: float) → void:
# Add gravity
if not is_on_floor():
velocity.y += GRAVITY * delta

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

# Handle horizontal input
var direction := Input.get_axis("ui_left", "ui_right")
if direction:
	velocity.x = direction * SPEED
	animated_sprite.flip_h = direction < 0
	animated_sprite.animation = "run"
else:
	velocity.x = move_toward(velocity.x, 0, SPEED)
	if is_on_floor():
		animated_sprite.animation = "idle"

# Move the character
velocity = move_and_slide(velocity, Vector2.UP)

# Play animation
animated_sprite.play()

link to video :Microsoft OneDrive


please can someone point me in the right direction

Like the error message says, your script says extends CharacterBody2D at the top, but the node it’s attached to is actually an AnimatedSprite2D. Can you show the node the script is attached to?

2 Likes


is this it?

Maybe because you said “animated_sprite.animation = jump” Instead of: animated_sprite.play(“jump”)?

I dont use godot 4.1, i use godot 4.4 so im not sure if godot 4.1 is like this but yeah.

And i don’t see an “AnimatedSprite2D” in your tree, Does it even exist?

You’ve probably attached this script to the wrong node accidentally.

Check your character “FROG3D” scene, if it has a AnimatedSprite2D with a script attached, then you probably have to change which script it has, or remove the script.

1 Like