Am trying to ma the enemy follow the player,
but problem: I can refer to the player (or the player scene) in the script.
The Player and Enemy are both in the root folder
THIS IS MY CODE BELOW:
extends KinematicBody
var path = []
var path_node = 0
var speed = 10
onready var nav = get_parent()
onready var player = $"Player"
func _ready():
pass
func physicsprocess(delta):
if pathnode < path.size():
var direction = (path[pathnode] - globaltransform.origin)
if direction.length() < 1:
pathnode += 1
else:
moveandslide(direction.nomalized() * speed, Vector3.UP)
func moveto(targetpos):
path = nav.getsimplepath(globaltransform.origin, targetpos)
path_node = 0
func onTimertimeout():
moveto(player.global_transform.origin)