Camera Motion Error

Godot Version

4

Question

Hi! I am trying to code a 3d game, and make a camera movement system along with it. Here is my code

extends Node3D

@export var sensitivity := 5
var player

func _ready():
player = get_tree().get_nodes_in_group(“Player”)[0]
$SpringArm3D/Camera3D.look_at(player.get_node(“LookAt”).global_position)
pass

func _process(_delta):
global_position = player.global_position
pass

func _input(event):
if event is InputEventMouseMotion:
var tempRot = rotation.x - event.relative.y / 1000 * sensitivity
rotation.y -= event.relative.x / 1000 * sensitivity
tempRot = clamp(tempRot, -1, 0)
rotation.x = tempRot

It says “Out of bounds get Index ‘0’ (on base ‘Array[Node]’)” as an error. I don’t get what this means, for i am a noob (first game ever). Can someone please find what may be the problem? Thanks.

It means that the array is empty and that there are no nodes the “Player” group within the scene tree.

1 Like

maybe you didnt add the player to the group?

1 Like

Thank you. This helped me. I initially had the player in the group, but i must have deleted it by accident.

I must’ve deleted it by accident. i replaced it, and it started working again. Thanks!