Lost on Get Simple Path (Godot 3.x)

Godot Version


Before anyone says it, I know… I even feel like a dunce rn, and this test isn’t the best setup.

I can’t, for the life of me, get the location of the player character for my enemy to move towards. For the test, I don’t need the enemy to continuously switch to where the player moves, I just want the enemy to move.

extends RigidBody

export var movement_speed: float = 4.0

onready var navigation_agent = get_node("NavigationAgent")

onready var Player = get_node("../Player")

func _ready() -> void:


func _process(delta):

move_toward(navigation_agent.get_target_location().x, 0, navigation_agent.get_target_location().z)

look_at(navigation_agent.get_target_location(), Vector3.UP)

The Player and Zombie are both parented to the world. For some reason, the Player.position throws an invalid index error, even though I dragged/dropped the Player node right into the code when I was making this. Please help me figure out why I can’t get this to run?

Thank you.

PS: I know Navmeshes and Navigation agents are deprecated. I am simply trying to grasp the basics of navigation.

Why is the target_position declared in the ready method?
It might be important to use player.global_position, maybe that’s why it is invalid?

Do you have a navigation layer used(assuming you use a tilemap)? Without it, the enemy doesn’t know where to move.

I actually made a script similar to this, if you want me to send a screenshot of it, I could do that.

This is all of the code needed. Don’t worry about the whole “in_shape” thing, it’s not relevant for the problem. I hope this helps you, if you have a question, please ask.
Have a great day :slight_smile:

I can’t get Player.global_position… It’s an invalid index.

That probably means that you are not properly getting at the Player node. Try to make sure the path is correct

I drag and dropped the player right into the code. It’s correct.

I see, then maybe it is the capitalization? I see the name of the variable there being player but you are trying to access Player instead

That didn’t help… Still an invalid index. I realize I accidentally set get_target_location instead of set, but fixing that didn’t work either.

To show where the objects are in game…
Screenshot (1017)

The OP is using 3.5, not 4.x

It’s global_translation in 3.x, not global_position

1 Like

Oh, sorry, did not realite that

THANK YOU! This was driving me insane!


NVM… Enemy still doesn’t move… Ugh. He instead scales and rotates to try to reach the player.

You aren’t using the navigation at all, you need to employ the callbacks, see:

Apologies, I left my old engine and never fully understood navigation there, either. I honestly have no idea what I’m doing, and the tuts I’m finding are not for my Godot version.

You need to use get_next_location instead of the target position, and check for updates, see this demo

That demo uses a navigation server, though, yes? Not the system I’m using rn just to practice. I could use the nav server, but I don’t understand either method.

It does not, it uses the agents just like you do

It only uses it for debugging, as you can see in the code, just ignore that part