I have an AI which follows the player using Navmesh, but it goes into the player. I want it to stop near the player so it won't go into it. So far, this is my code:
var path = 
var path_node = 0
var speed = 7
onready var nav = get_parent()
onready var player = $"../../player"
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)
path = nav.get_simple_path(global_transform.origin, target_pos)
path_node = 0
This is being made in 3D.