Can't find "target_position"/"set_target_position"

Godot Version

Godot 4.2

Question

I am new to Godot engine, and i’m having a hard time with something.

I’m trying to make a simple enemy AI, just the basic for now, and to start i want to make the enemy follow where the player is. But, the code that i’m using (which is from a youtube video), uses something that after some time messing around, i can’t seen to find it anywhere, like it doesn’t even exists? And this part of the code is the “target_position”. I’ve already tried set_target_position also.

Below will be the code that i’m using in question, if you all want some screenshots or anything i’m at disposal.

extends CharacterBody3D

var player = null

const SPEED = 6.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.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
move_and_slide()

do you mean this?:

nav_agent.target_position = player.global_transform.origin

Hello, i’ve made the exact same post as this one, and someone already pointed that out, but here’s the problem that’s giving me:

Putting now “nav_agent.target_position = player.global_transform.origin” gives this line of error => Invalid set index ‘target_position’ (on base: ‘null instance’) with value of type ‘Vector3’.

Can you show your AI-scene-tree? the nav_agent is not set

1 Like