Janky & Weird Pathfinding Fix?

My AI script movement is very janky and it will also create a path drastically different from where it’s suppose to go as you will see in the following video

so as you can see the movement is very weird and you’ll notice that the pathfinder creates waypoints far away from the target that’s being chased


The npcs are network owned by the server, observe the usage of self.RootPart:SetNetworkOwner(nil)

PathfinderAI:findTarget() is NOT called again until the current target is reached

PathfinderAI:visualizePath() allows you to see the Pathfinding waypoints by creating white dots

https://pastebin.com/ex8q12pt


there aren’t any errors in the script but it’s weird that it behaves this way

I prefer not to post in #help-and-feedback:scripting-support because I do not want to expose my code to public due to the category being accessible by anyone.

I’ve moved this to Scripting Support as you’re looking for help with a specific thing as opposed to a broader subject. Also, you’re going to want to show your code so people can pinpoint what the issue may be. :stuck_out_tongue:

2 Likes

I really don’t understand what you’re trying to do here, and how we can help you considering you don’t want to post your code. However, from what I understand is that the AI is stopping every once and a while when chasing somebody.

This is probably an issue with the :findTarget function, as once the target has been reached it’s re-called, and so what ends up happening is that it has to calculate it all again, which is the reason for the janky AI.

2 Likes

Please refer to the link I already included via a pastebin in the OP


No, I already address this misconception please consider;

if you direct your attention to the output and notice that it never print(“Target Reached!”)

the problem is in moveToFinished_Ev particularly in if self.isChasingTarget then end you might find a solution by looking at that section specifically

3 Likes

Please note that I did not carefully go through your code line by line, but from the video, it looks like your pathfinding script is trying to travel to a different target at every iteration instead of sticking to the closest one. Check by putting different target names in the workspace and printing the target’s name every time. If it is sticking to the same target then ignore this comment.

1 Like

It kinda took me a while to read through because i have class at this time. Idk if this is any problem, but is there any possibility that self.TargetPosition is altered upon the current target running, while the :Createpath is also forcefully changing it due to the parameter?

(seems like u have left by the time i came up with this so ima post here :P)

1 Like

Never mind. I am talking non-sense here.

1 Like

I think I am now confident with what I found. On Line 116 of the pastebin, it seems like it is temporarily setting the target position to somewhere on the baseplate when the ai reaches the end point of previously calculated path, which gets re-calculated splits of second later when the closest target moves again.

1 Like

You are right!!!

I’ll fix that and then report back on how it behaves.

I was working on this until 6 AM so my bad

1 Like