_physics_process function is not being called correctly:

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

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.

Hi.
so the code above works? But if you put “move_to(player.global_transform.origin)” into the “_physics_process()” function it dont work?

klaas | 2021-07-13 12:43

This is exactly that happening.

MxtApps | 2021-07-13 14:25

There’s no underlying reason why you shouldn’t be able to call functions within _physics_process.

If you comment out the other stuff and put a print command in your function, and then call it from _physics_process
Does it print?

Yuminous | 2021-07-13 14:38

can you show us the version wich dont work? Maybe the error lies inside the way (or where) you call it?

klaas | 2021-07-13 14:49