Hello! I'm trying to set an enemy to follow my character but whenever I run the game I get "Invalid get index 'global_position' (on base: 'Nil'). error. No idea why.
The player and the enemy are different scenes that each have their own "player" and "enemy" node groups. And these scenes are instatiated in the game level scene
The enemy code starts with:
extends CharacterBody3D
const SPEED = 5.0
const JUMP_VELOCITY = 4.5
var gravity = ProjectSettings.get_setting("physics/3d/default_gravity")
@onready var navigation_agent_3d = $NavigationAgent3D
var player: CharacterBody3D
var player_position: Vector3
func _ready():
var player = get_tree().get_first_node_in_group("player")
func _physics_process(delta):
player_position = player.global_position
navigation_agent_3d.target_position = player_position
var next_position : Vector3 = navigation_agent_3d.get_next_path_position()
(...)

I'm using Godot 4.2.2.Stable
Does anyone know what is wrong?