Attention | Topic was automatically imported from the old Question2Answer platform. | |
Asked By | Cobra! |
I’m trying to make my AI follow the player by using pathfinding, but the problem is that it spazzes out like crazy, and I have no idea what’s causing it to do so.
Here’s my code:
func _process(delta):
if targetSpottit:
if notTooClose(): # basically checks the distance to the target
if navMesh:
followTargetPath(target.translation, delta)
#testFunc(target.translation, delta)
else:
translate(followTarget(target.get_translation(), delta))
navMesh = $"../Level"
nextAnim = rinninAnimation
closeEneuch = false
elif !closeEneuch:
look_at(minusY(navMesh.get_closest_point(target.translation)), Vector3(0, 1, 0))
closeEneuch = true
else:
turn_to(navMesh.get_closest_point(target.translation), delta)
attack_logic(delta)
elif $TargetRay.is_colliding():
setTargetSpotted(true, $TargetRay.get_collider())
else:
nextAnim = staundinAnimation
func followTargetPath(target, delta):
if followPath.size() > 0:
if currentPathNode < followPath.size() - 1 and pathTimer > 0:
translate(followTarget(followPath[currentPathNode], delta))
if translation.distance_to(followPath[currentPathNode]) < 10 and pathTimer > 0:
currentPathNode += 5
print("Next")
pathTimer -= delta
else:
translate(followTarget(target, delta))
if translation.distance_to(navMesh.get_closest_point(target)) > minDistance * 2:
followPath = Array()
currentPathNode = 0
pathTimer = PATH_COOLER
else:
var begin = $"../Level".get_closest_point()
var p = $"../Level".get_simple_path(translation, target, false)
return Array(p)
followPath = $"..".getPath(translation, target)
func notTooClose():
return translation.distance_to(navMesh.get_closest_point(target.translation)) > minDistance
Here’s a video demonstrating the problem: https://youtu.be/Ba6wOIoyl30
Here’s a download link to the project itself: http://www.mediafire.com/file/5gcai78w7p5d5j7/project.7z
What am I doing wrong?