Questions about pathfinding

I know nothing about pathfinding beyond reading the debhub page on it.

“ComputeAsync” sounds like a resource intensive function. Since the target is always moving, I would be calling ComputeAsync at each waypoint the NPC reaches.

Would I be able to have 100 NPCs on the map targeting players at once?

Also I found this thing called “A*”. Is it better/faster than Roblox pathfinding? Should I look into it more?

Also I want NPCs to be able to pathfind up ladders.

1 Like

Compute Async is only run once per path, so it wouldn’t be as intensive as you may think.
Unless you are recalculating the path at each waypoint

How will the NPC then change direction when the player moves?

You consistently change it’s direction in a loop, but make sure to optimize your loop.

Okay but no one is answering my original questions.

How performant is this?
Can I have hundreds of NPCs pathfinding players (constantly calling ComputeAsync) at the same time?
What the heck is “A*” and should I use it?
How do I get it to work with ladders?

It depends on what method you use for your npcs. OOP will help you maintain a good performance. There should be a tutorial on that if you don’t know what it is. It’s a pathfinding method which uses a service so obviously it’s quite performant, but don’t let that scare you into thinking you can’t use it at all. You just have to make sure that you use it in an efficient way.

My guy… what are you saying? OOP is not a “pathfinding method”

If you don’t have the answers please refrain from posting.

1 Like

OOP can be used for npcs to reduce performance.

FYI: You should probably change your title to ‘Questions about pathfinding’

Every NPC will need it’s own path because each NPC is in a different location and each player is in a different location. There is no way that I can consolidate the pathmaking into “less paths” using OOP.

I’m not looking to reduce performance

okay

Each npc will need it’s own path, I’m just saying it depends on how you make your npc script. That’s what determines how performant it is.

If you’re not looking to reduce performance then why are you asking if the pathfinding is performant or not? I’m confused… It’s a service that generates points for your npc to go so it’s pretty self explanatory yes it is performant (depending on how much it’s used like every piece of code on roblox) I already told you that from the post above if you can read.

Constantly recalculating paths for multiple npcs is bad for performance overall. Just having a lot of npcs in general isn’t good, especially if you want mobile players to play.

A* is a different method of pathfinding that doesn’t use Roblox’s service. I don’t think it’s actually all that better for performance, and also, it’s mainly used for flat surfaces only

For ladders, there’s no built-in way to detect them. Maybe using the pathfindingmodifer passthrough and raycasting, you can manually script in a climbing system?

also, OOP npc programming is most commonly used to get rid of the need for humanoids in npcs, which improves performance by a lot

3 Likes

because I want to increase the performance of my game not reduce it. The only time I can think that I would want to reduce it is if I am making a “lag simulator”


Okay so I wont look into it unless I have a need to

Can you elaborate, you are basically saying “making NPC’s without humanoids is more performant”?

A* (or A-Star) is pathfinding for 2d space, It’s used in 2d grid games, like Tower Defense games, so It’s not probably faster than original pathfinding and It’s complicated to make and use, so I recommend using PathfindingService

2 Likes

He’s telling you as it sounds bro, also OOP is useful for having 1 script that manages the entire bunch of NPC’s you have in your game. It’s very useful and has less performance cost.

Yeah, roblox’s humanoids can be slow and laggy a lot, so if you want a bunch of NPCs at once, it’s best to not have humanoids in any of them

so then my last question is how can I make pathfinding work with ladders?

basically anywhere the player can go I want the NPC to be able to go and players can climb ladders.

this might help in making climbing npcs

1 Like

okay thanks.

Thank you @Wyzloc @zynonical @JaceMorphing @Orbular3

I will mess around with pathfinding and see if I can make a system that’s hopefully lag free. (idek if it lags to begin with, maybe I can have a thousand NPCs without lag and I’m asking for support unnecessarily :man_shrugging: )

2 Likes

You should try reading Roblox’s article on Character Pathfinding | Roblox Creator Documentation. It explains many aspects of using pathfinding. For attempting to optimize the code, you could use Path | Roblox Creator Documentation and Path | Roblox Creator Documentation and only recompute when one of these is fired.

Alternatively, a more performant approach would be to detect when the next waypoint is reached (using Humanoid | Roblox Creator Documentation) and then check to see if the path is blocked using Path | Roblox Creator Documentation. If it is, then you could try recomputing the path.