TL;DR - I’m trying to make AI that only walks around on specific parts.
The idea is that it can be used to make NPCs walk around train stations and spawn different amounts of the NPCs depending on the time of day.
Anyway, the trouble is I have no idea where to even start with how to check what parts they are walking and I’m not really sure how I can make them choose a point on the platforms to walk to (but I can probably use maths to make sure that the point is on the part so it shouldn’t be too much of an issue)
Here is just an idea. Around the path, you surround it with parts, that way the NPCs cannot walk outside of the path. Then put all of those parts in a folder. Then when a player joins, on the client side you destroy the folder with all the parts. That way the players can walk anywhere but the path finding in the server only works on path.
Interesting - I already use collsion groups so that could also work. Though I’m not sure I’m keen on having lots of extra parts at every station in the game.
To check what parts they’re walking on, downcast with the pathway parts whitelisted (meaning the raycast is only performed against pathway parts). In terms of picking a point to walk to, well, just call MoveTo to that point? Do you need some kind of specific implementation here that isn’t as simple as calling MoveTo towards your desired location (i.e. only moving to valid neighbouring squares)?
My thinking was spawn them at the entrance and get them to walk to a spot on the platforms to wait until a train arrives. When it arrives they would then walk to the doors and despawn. Getting them to go to the doors should be easy enough but I was concerned about them deciding to walk on the tracks or something when going to a spot on the platforms which is why I was thinking of how I could check what they are walking on.
This is a “nav mesh”, if that helps your googling.
ROBLOX generates one automatically with some really complex stuff when you use PathfindingService. Unfortunately they don’t currently provide a ton of tools to tweak the navmesh.
However you could implement your own relatively simply if you can make some assumptions:
- The parts are always rectangles
- The parts are always axis-aligned (no 45 degree rotations, e.g.)
- The parts are always on the same plane (i.e. flat) and there’s no vertical movement
I’ve just tried out the walls thing but the NPCs are too stupid to realise it’s a wall and they can’t walk through it.
I was hoping they would automatically go around but nope.
One Quick way is by using collision groups and disabling collision on the part you don’t want it to stand on. The NPC won’t fall through because of Roblox pathfinding, unless pushed off. So if you’re doing this method, make it so they can’t collide with other NPCs or real players.
I’ve just tried to do that but they run right off the edge into the void
It’s like they are too stupid to realise that the stuff that has collisions off will make them fall.