0 votes

Hi!
I am making a 3D game that I need that the enemy follows the player.
I want to use the navigation get simple path gdscript function, but I do not know how I can get and use the value.
Someone can tell me how I can do it?
Thanks.

in Engine by (348 points)

1 Answer

+1 vote
Best answer

get_simple_path() basically gives you an array of points, so

var the_path = Navigation.get_simple_path(start_point, end_point) #gets the path
your_player.look_at(the_path[3]) #looks at the 4th point of the path array

Typically you'll want a KinematicBody that walks along the this path like this.

move_and_slide(global_transform.basis.xform(Vector3.FORWARD))
look_at(the_path[current_point]) #current_point is an int variable
if global_transform.origin.distance_to(point[current_point]) < 1:
    current_point += 1

It's also possible to use a Path node and a PathFollow node but they're a bit more arduous to work with in this context so I wouldn't recommend it.

by (3,223 points)
selected by
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 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 webmaster@godotengine.org with your username.