Hi all! 🙂
I have a problem with an enemy path-finding.
My goal is to have a path with few points on the map and make enemy to follow every path point continuously.
When the player will be in the enemy area, the enemy will start following a player instead of path points. (I still didn't get here because the basic path follow not working)
What I have:
• Enemy node (kinematic body) with script
• Enemy path node with few points in the 3D space (map)
What's the actual problem:
• Enemy doesn't follow the path correctly and continuously.
• Enemy is not placed correctly on the ground when following a path, he's flying a little in the air.
I tried to do this in different ways but still without the result. I'm still new to 3D so I'm just trying to do things in multiple ways and learning which one is the best.. 😃 But here, no one of them works..
Here how the path looks like:

Here's my enemy code to start following a path:
First I init the path and get the first point of the path curve:
func path_init():
var _count = cPath.get_point_count();
var _pointTo = cPath.get_point_position(0) + get_parent().get_node("ReddiePath").global_transform.origin;
move_to(_pointTo);
init = true;
Finding the points from the curve works fine. I tried to spawn a mesh on the position where I tried to go and that works correctly.
move_to func:
func move_to(_location):
var _target = _location;
path = nav.get_simple_path(global_transform.origin, _target, true)
And finally _physics_process:
var goal = Vector3()
var step_size = delta * speed
if path.size() > 0:
#move to point when the path exists
var destination = path[0]
goal = destination - translation
if step_size > goal.length():
step_size = goal.length()
path.remove(0)
goal = goal.normalized()
move_and_slide(goal * speed, Vector3.UP)
else:
#if he reach the point find next one
if init:
path = []
var _count = cPath.get_point_count();
pathPos += 1;
if pathPos >= _count:
pathPos = 0
var _pointTo = cPath.get_point_position(pathPos) + get_parent().get_node("ReddiePath").global_transform.origin;
move_to(_pointTo);
Yeah.. The result is not as I expect.. Enemy just randomly moving and behave really strenge.
Can anyone give me an impulse what I made wrong? I'm new to 3D. Thanks a lot!
Have a nice day!