The Godot Q&A is currently undergoing maintenance!

Your ability to ask and answer questions is temporarily disabled. You can browse existing threads in read-only mode.

We are working on bringing this community platform back to its full functionality, stay tuned for updates. | Twitter

0 votes

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
        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():

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.

Godot version 3.3.2
in Engine by (116 points)

so the code above works? But if you put "moveto(player.globaltransform.origin)" into the "physicsprocess()" function it dont work?

This is exactly that happening.

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?

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

Please log in or register to answer this question.

Welcome to Godot Engine Q&A, where you can ask questions and receive answers from other members of the community.

Please make sure to read Frequently asked questions and How to use this Q&A? before posting your first questions.
Social login is currently unavailable. If you've previously logged in with a Facebook or GitHub account, use the I forgot my password link in the login box to set a password for your account. If you still can't access your account, send an email to [email protected] with your username.