Zombie does not follow the player

:information_source: Attention Topic was automatically imported from the old Question2Answer platform.
:bust_in_silhouette: Asked By Skyline

Hello, can anyone help me?

I used code like this: onready var target = get_node (“/ root / Main / Player”) does not seem to solve

I can not solve it, I did not understand what gave the error code:

code (Image):

C Erro: Condition ’ r_error.error != Variant::CallError::CALL_OK ’ is true. returned: __null
C Origem: modules/gdscript/gdscript.cpp:129
C Função: _create_instance

Image:

Project zip

:bust_in_silhouette: Reply From: SIsilicon

##English##

The node path is incorrect. What I would recommend doing instead, is to put the player’s node in its own group. Better do it in the editor.
Then, when you need to retrieve the player node, just do this.

var player = get_tree().get_nodes_in_group(your group name)[0]

##Español##
La ruta del nodo es incorrecta. Lo que recomendaría hacer en su lugar, es poner primero el nodo del jugador en su propio grupo. Mejor hacerlo en el editor.
Luego, cuando necesite recuperar el nodo del reproductor, simplemente haga esto.

var player = get_tree().get_nodes_in_group(tu nombre de grupo)[0]

No olvides on_ready.

SIsilicon | 2018-10-11 20:13

Thanks, help me.
why use [0]?

Can I put quotation marks with or without?
example:
var player = get_tree().get_nodes_in_group(“player”)[0]
or
var player = get_tree().get_nodes_in_group(player)[0]

Skyline | 2018-10-11 20:32

Since multiple nodes can be in the same group, get_nodes_in_group returns an array rather than a single node. So the [0] is required to get the first (and possibly only) node in that array.
Also since you need the name of the group, you must put in a string.

“Hey should I type in English or Spanish?”

SIsilicon | 2018-10-11 20:54

type in English only

I added to the group “player”
to get the player I do

var player = get_tree (). get_nodes_in_group (“Player”)[0]

but the error remained the same

Image:
Zombie AI code1.PNG - Google Drive

Skyline | 2018-10-11 21:11

Try this.

var player = null
onready player = get_tree().get_nodes_in_group("Player")[0]

SIsilicon | 2018-10-11 23:42