I’ve been trying to run a navigation enemy with this script
extends CharacterBody3D
var player = null
const SPEED = 4.0
@export var player_path : NodePath
@onready var nav_agent = $NavigationAgent3D
func _ready():
player = get_node(player_path)
func _process(_delta):
velocity = Vector3.ZERO
nav_agent.set_target_position(player.global_transform.origin)
var next_nav_point = nav_agent.get_next_path_position()
velocity = (next_nav_point - global_transform.origin).normalized() * SPEED
look_at(Vector3(player.global_position.x, global_position.y, player.global_position.z), Vector3.UP)
move_and_slide()
and im getting an error for
player = get_node(player_path)
it says Invalid get index ‘global_transform’ (on base:‘null instance’) as an error
i’ve been using a tutorial and i don’t know how to fix it really, mainly cause i just started godot out 2 days ago, also i am a literal boomer with this type of stuff so any suggestions or alternate code i can use instead of this would be greatly appreciated
Thanks,
ZKING24