0 votes

I want to access player's position on enemy nodes, so they can chase the payer. What good ways are there to do this?

asked Jul 16, 2019 in Engine by KijeviGombooc (139 points)

2 Answers

0 votes
Best answer

What I found to be useful, is adding all enemies to "ENEMIES" group, then make then have a method "add_player" and call this method of the group on player script.

answered Jul 16, 2019 by KijeviGombooc (139 points)
0 votes

You can use get_node() to access the player's position. Take a look at the documentation for more information about it: https://docs.godotengine.org/en/3.1/classes/class_node.html#class-node-method-get-node

Here is an example: get_node(“/root/player”).get_position()
You can also use $ instead for short-hand: $player.get_position();

answered Jul 16, 2019 by sparkart (327 points)

I feel like this is not good, because the relation of the player and the enemy nodes might chance overtime, so the sript(s) need change too. What I found to be useful, is adding all enemies to "ENEMIES" group, then make then have a method "add_player" and call this method of the group on player script.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read How to use this Q&A? before posting your first questions.