Pathfinding on terrain

Alright, There might be something wrong with my code since i’m very very new to scripting

You should move this local Path = game:GetService("PathfindingService"):CreatePath(PathArgs) out of the move function. No need to recreate that over and over unless you need to change the path args. It actually has to recalculate the navigation mesh when this is called.

I’m curious if maybe the path is failing and it doesn’t have any waypoints. What happens if you put the waypoint parts into a model and clear it each time the move function is called? I’m guessing it would show that the path doesn’t have any waypoints

So ur saying all waypoints into a model and when its done walking remove that model?

EDIT: Still not.

EDIT: I’m gonna go to bed i’ll try smth tommorow

Usually when the monster can see the player, you can cast a ray to make sure, then use :MoveTo as pathfinding is really harsh on the server. This will both boost your performance and make your monster seem a little smarter as he can both go through a maze and follow the player directly.

Also always make sure that when you DO pathfind, the pathfinding model returns success rather than a blocked path.

So what you would do is cast a ray, from monster to player, preferably when the magnitude is less than a certain amount, if it hit you use :MoveTo to move to the player’s Torso, else you can pathfind until the monster’s ray hits the player.

This completely beats repeating pathfinding to the player as you don’t really need to pathfind when the player is right in front of your monster.

2 Likes

To be clear, this won’t fix it. This only shows us something. Unless you create the model you don’t need to remove it, you can just call :ClearAllChildren() on the model or something to remove the waypoint indicator parts.

If at some point there are no parts then that would confirm the theory.

Is there a numerical condition that this hill is presenting that you could anticipate in order to provide the AI a backup plan or else if, in order to at least prevent it from freezing in place.

I’m assuming that the pathfinding is originating from the monster’s primary part which likely it’s torso… What if the point from which the monster is taking it’s information from is offset (raised up high enough) a significant amount in order to provide the monster a broader data set when it encounters conditions like this Hill ?

I have no clue how raycast works, So i’m prob pausing the monster for now and taking time to learn it.

Another possible option: If there are only a few problem spots on the map, you can detect when the monster goes into those locations (by region or invisible block) and then just give it a pre-scripted MoveTo() that gets it through the problem spot.
For my NPCs I usually have some code that just checks that their position isn’t staying the same, and if they seem stuck I take some recovery action, even if that means random MoveTo()s, or random (short) teleports.

1 Like