![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | KijeviGombooc |
I want to access player’s position on enemy nodes, so they can chase the payer. What good ways are there to do this?
![]() |
Attention | Topic was automatically imported from the old Question2Answer platform. |
![]() |
Asked By | KijeviGombooc |
I want to access player’s position on enemy nodes, so they can chase the payer. What good ways are there to do this?
![]() |
Reply From: | sparkart |
You can use get_node()
to access the player’s position. Take a look at the documentation for more information about it: Node — Godot Engine (3.1) documentation in English
Here is an example: get_node(“/root/player”).get_position()
You can also use $ instead for short-hand: $player.get_position();
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.
KijeviGombooc | 2019-07-16 18:26
![]() |
Reply From: | KijeviGombooc |
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.
![]() |
Reply From: | k3nzngtn |
export (NodePath) var playerNodePath
func _physics_process(delta):
var player = get_node(playerNodePath)