I am looking for an efficient solution to get a random position on random terrain that AIs can path to for something like a “wandering” movement.
I am deciding the AI position on the server, and I am building the AI and making it pathfind to the position that the server gives that AI on the client, so I cannot just use bodymovers and raycasting to make the AI wander aimlessly.
I have not yet started doing this problem, but right now I am thinking of selecting a random X and Z value and raycasting down to check if it is a viable position.
The terrain would look something like this (with more foliage):
I’m not sure if this is even a some-what decent way of doing this, but depending on how large your map is, perhaps you could create a bunch of decently-sized parts that cover different areas of the terrain you wish for your AI’s to be able to travel to, and then you can use math.random on each axis to get a random position out of the part.
Can clarify further if you’re at all interested in this method.
“This is not really rocket science. We do use a dynamic spatial partitioning structure; we use it both for broadphase for physics simulation and for ray casting. The structure is reasonably efficient (although the longer the ray is the slower it is to query it so shorter rays are better than longer rays).” - zeuxcg
Raycast from old position to now position > no hit not noclipping
Hit > Raycast from current pos to the first position we cast from > if hit then we went through a part, check angles and normals as we might’ve clipped a corner
Other hit option > raycast from current pos to original cast pos > no hit > currently inside the part
You do it from the server, as the client can just delete parts and completely negate it. In this case they can’t really avoid it. Now since rays can be costly the bigger they are, if a player teleports that’s a hit. Instead of taking it do a check to see the distance between the position before doing the rays. If it’s too far apart just skip the rays as they teleported and go straight to whatever ur punishment is.
I recommend just teleporting them straight back to where they were, doesn’t punish laggy players with a ban and annoys exploiters.