Robust Raycasting Grid Generator

I made this for some AI in an upcoming new gamemode in Survival: Arena, but I just couldn’t let such a juicy piece of code sit in my game alone. Basically, this raycasts a grid of defined size from the sky to detect obstacles, then raycasts between those gridpoints to see if the paths are traversable. It has a bunch of nice, easy-to-modify globals and it doesn’t seem to chunk a bunch of CPU.

I stick this in ServerScriptService and it automatically generates a model called “Data” in itself, which contains a LOT of Vector3Values (the gridspots) and each of those contain ObjectValues (pointers to other Vector3Values which can be traversed to, according to the raycast). The GetGridByVector3 function inside the script additionally returns the Vector3Value belonging to the grid space in which the given position is.

So I guess that’s a usage guide.

EDIT: If you want a visual representation of how it works, uncomment “test()” in “main.”

1 Like