How can I a position in a Region3 that's unobscured and the same every time unless something in region changes?

I’m trying to make an AI that will try to get anywhere inside of a player’s base (128 x math.huge x 128). Roblox’s pathfinding is really amazing sometimes, but there’s one problem I’ve been having with it: if the specific point you try to pathfind to is obscured by anything, a path can’t be computed. This means that I need to have a method of finding some place inside the base’s region that:

  1. Isn’t obscured by any parts
  2. Isn’t completely random (if an AI gets halfway to an entrance of the base, and is forced to recompute its path for whatever reason, it might so happen that the new random position means it has to go all the way back around the other side of the base to get there which would just be kinda not smart and unnecessary.)
  3. Is as close to the ground, or as close to the AI as it can get

I’ve tried sequentially top-down raycasting to find the lowest room’s floor and ceiling, I’ve tried splitting the base into 4x4x4 Region3s and just testing them sequentially until I find two on top of eachother that are empty. And I’ve noticed, the less empty space there is in a base, the more laggy these both become. The server slows down to the point everything appears to be in slow motion, and this is when I test with only a small number of npcs in the server, and I need this to be fast (I want my AI to be really responsive)

If anyone has any ideas on how to do this quickly and efficiently, I’d really appreciate it

2 Likes

I’m guessing I made my title a little too long, lol
Still having trouble with this, but I dunno if I should make a new post for it or not

One method that might work for your game is repeatedly picking a random point in a circle around the NPC until you find one that satisfies the conditions. By limiting the radius of the circle you circumvent issue #2, and if you want to ensure that you always find some valid position, you can grow the search radius after failing a certain number of times in a row.

2 Likes