I'm having a problem with my pathfinding.

I'm trying to use the Navigation and NavigationMesh to do my pathfinding, but I'm running into some problems.

The AI that is doing the pathfinding is just running off on one direction and doesn't stop.



Here's the level I'm testing on, with the NavMesh highlighted:



Upon printing it for debugging, the coordinates are way off, like I suspected:



The first 3 vectors are the path nodes

The bottom Vector3 is the actual position of the player, which the AI is supposed to be chasing.

Here's my code:

#AI.gd onready var currentTarget = get_node(target) var previousTarget var currentDirection = Vector3() export(float) var turnSpeed = 1 var enemySpotted = false var navMesh var followPath = Vector3Array() var currentPathNode = 0 const PATH_COOLER = 0.3 onready var pathTimer = PATH_COOLER export(float) var minDistance = 3.5 export(float) var maxDistance = 50 var diff var dist func AILogic(delta): dist = get_translation().distance_to(currentTarget.get_translation()) if enemySpotted: # If the enemySpotted flag is true if currentTarget.dead() or dist > maxDistance:# If the target is dead or too far away. if !previousTarget: resetTargets() # Reset the targets enemySpotted = false # Set the flag of "enemySpotted" to false, returning the AI to it's ordinar state. else: currentTarget = previousTarget previousTarget = null followPath = Vector3Array() currentPathNode = 0 elif dist > minDistance: #and it isn't too close tae it if navMesh: FollowTargetPath(currentTarget.get_global_transform().origin, delta, enemySpotted) #translate(FollowTarget(currentTarget.get_global_transform().origin, delta, enemySpotted)) else: navMesh = get_tree().get_root().get_node("Level").navMesh else: # If the AI IS close enough to the player. followPath = Vector3Array() currentPathNode = 0 turn_to(currentTarget.get_global_transform().origin, turnSpeed / 2, delta) fightingLogic(delta) # Go to the fightingLogic method, which takes care of the fighting mechanics. #This is where the following logic happens, it basically slowly turns to the target, and walks forward untill it's too close tae it, where it returns (0,0,0) to let the function # calling it know that it's too close to the target, for it to change target if it's not going after the enemy. func FollowTarget(target, delta, isEnemy): if get_translation().distance_to(target) > minDistance: turn_to(target, turnSpeed, delta) if abs(velocity.z) < topSpeed: velocity.z -= _acceleration * delta if isEnemy: nextAnim = wapen + "Rinnin" else: nextAnim = wapen + "Walkin" else: if !enemySpotted: changeAnim("Staundin 4", wapen + "Staundin") return Vector3(0, 0, 0) translate(velocity) return velocity func FollowTargetPath(target, delta, isEnemy): dist = get_translation().distance_to(currentTarget.get_translation()) if followPath.size(): if currentPathNode < followPath.size() and pathTimer > 0: var targetFollow = FollowTarget(followPath[currentPathNode], delta, isEnemy) if targetFollow.length() == 0: currentPathNode += 1 else: translate(targetFollow) pathTimer -= delta else: translate(FollowTarget(target, delta, isEnemy)) followPath = Vector3Array() currentPathNode = 0 pathTimer = PATH_COOLER else: followPath = navMesh.get_simple_path(get_translation(), target, false) for i in followPath: print(i) print(target) ----- #LevelMain.gd (Root Script) export(NodePath) var navigationMesh onready var navMesh = get_node(navigationMesh) setget , getNavMesh func getNavMesh(): if navMesh extends Navigation: return navMesh else: return 0

What am I doing wrong?