Hi,
I have this code:
extends KinematicBody
var path = []
var path_node = 0
var speed = 20
onready var navigator = get_parent()
onready var player = get_parent().get_node("Player")
func _physics_process(delta):
if path_node < path.size():
var direction = (path[path_node] - global_transform.origin)
if direction.length() < 1:
path_node += 1
else:
move_and_slide(direction.normalized() * speed, Vector3.UP)
func move_to(target_pos):
path = navigator.get_simple_path(global_transform.origin, target_pos)
path_node = 0
func _on_Timer_timeout():
print("Timeout")
move_to(player.global_transform.origin)
As you can see, the move_to
function updates the path between the player and the enemy, and I call it when the timer timeouts, and if I call it in the _physics_process
function, the enemy does not move to the player. How can I call that method from the _physics_process
function without getting this bug.
Thanks in advanced.