please help with this code from tutoiral

i was following a tutorial on how to make a doom like game in godot but i can’t get the player to work

code:

extends CharacterBody3D

@onready var animated_sprite_2d_1 = $CanvasLayer/pistolbase/PISTOL
@onready var ray_cast_3d = $RayCast3D
@onready var shoot_sound_1 = $pistolsound



const SPEED = 5.0
const MOUSE_SENS = 0.5

var can_shoot = true
var in_the_grave = false

func _ready():
	input.mouse_node = input.mouse_node_captured
	animated_sprite_2d_1_finished.connect(SHOOT_ANIM_DONE)
	$CanvasLayer/dead/Panel/Button.button_up.connect(restart)

func _input(event):
	if in_the_grave:
		return
	if event is InputEventMouseMotion:
		rotation_degrees.y -= event.relative.x * MOUSE_SENS

func _process(delta):
	if input.is_action_just_pressed("QUIT"):
		get_tree().quit()
	if input.is_action_just_pressed("RESTART_THE_WHOLE_LEVEL"):
		restart()
	
	if in_the_grave:
		return
	if input.is_action_just_pressed("pew_pew"):
		shoot()

func _physics_process(delta):
	
	var input_dir = Input.get_vector("MOVE_LEFT", "MOVE_RIGHT", "MOVE_FORWARDS", "MOVE_BACKWARDS")
	var direction = (transform.basis * Vector3(input_dir.x, 0, input_dir.y)).normalized()
	if direction:
		velocity.x = direction.x * SPEED
		velocity.z = direction.z * SPEED
	else:
		velocity.x = move_toward(velocity.x, 0, SPEED)
		velocity.z = move_toward(velocity.z, 0, SPEED)

	move_and_slide()


func  restart():
	get_tree().reload_current_scene()

func  shoot():
	if !can_shoot:
		return
	can_shoot = false
	animated_sprite_2d_1.play("SHOOT")
	shoot_sound_1.play()
	if ray_cast_3d.is_colliding() and ray_cast_3d.get_collider().has_method("kill"):
		ray_cast_3d.get_collider().kill()

func SHOOT_ANIM_DONE():
	can_shoot = true

func kill():
	in_the_grave = true
	$canvaslayer/dead.show()
	input.mouse.mode = input.mouse.mode.visible
	
	

errors:

Line 16:Identifier “input” not declared in the current scope.
Line 16:Identifier “input” not declared in the current scope.
Line 17:Identifier “animated_sprite_2d_1_finished” not declared in the current scope.
Line 27:Identifier “input” not declared in the current scope.
Line 29:Identifier “input” not declared in the current scope.
Line 34:Identifier “input” not declared in the current scope.
Line 69:Identifier “input” not declared in the current scope.
Line 69:Identifier “input” not declared in the current scope.

Case matters. It’s Input, not input.

1 Like

thank that removed most the errors but I have no idea on the fix these ones

Line 16:Cannot find member “mouse_node” in base “Input”.
Line 16:Cannot find member “mouse_node_captured” in base “Input”.
Line 17:Identifier “animated_sprite_2d_1_finished” not declared in the current scope.
Line 69:Cannot find member “mouse” in base “Input”.
Line 69:Cannot find member “mouse” in base “Input”.

Case and spelling matter. It’s “mode”, not “node”.

Input.mouse_mode = Input.MOUSE_MODE_CAPTURED

thanks but i still need help with line 17

There should be a period between the var name and its finished property
animated_sprite_2d_1.finished.connect(SHOOT_ANIM_DONE)

I encourage you to take the time to learn some general programming if you don’t have any experience.

thanks but now i’m getting a debug error

invalid got index ‘finished’ (on base: ‘Animatedsprite2D’)

Docs say the signal name is animation_finished – AnimatedSprite2D — Godot Engine (stable) documentation in English