[SOLVED] Telling apart coastal and landlocked parts

I have quite a complex issue. My map is made out of thousands of parts and I use Raycasting to check if there’s a part in both X and both Z directions from the part. This system works well, apart from one issue:

I provide an image to better understand this problem:

  • In case number 1, there’re other parts surrounding the part from all sides, so it returns false (because there are no empty spaces), as expected.
  • In case number 2, there’re open spots in multiple directions, so it returns true (because there are empty spaces), as expected.
  • The case number 3 is the problem: my Raycasts detect parts from all sides, so it returns false (because it thinks there are no empty spaces), but it’s expected to return true (because the part is not fully surrounded).

I have no idea how to fix the issue (the case number 3). Any help will be gladly appreciated!


Bumping this topic, because I still haven’t found a solution.

Is the raycast location in the middle of the part?

The origin of the Raycast is in the middle of the part, yes.

You can try using 2 raycasts for each side of the part

Plus you can compare the X / Z length


What if there are multiple parts blocking the origin part and the open spot is between them?

What is the minimum part length?

1 stud is the minimum length of any part.

Are you generating the map programmatically? If so you should be able to figure it out easily while generating.

If not you could use GetPartBoundsInBox instead of raycasting (if all your parts are rectangles)

1 Like

In this case, I think Raycasting is not suitable for you.
You can create Region3 the same size of part and then use GetPartBoundsInBox.


Could you show me an example of how I would check for any empty spots using GetPartBoundsInBox?

Is it possible to fill empty spots with a parts named something like EmptySpot?

The map is too big for me to fill in all of the empty spots, so unfortunately, it’s not possible.

It’s more involved than I initially thought but should be possible.

Are all parts always rectangles and always aligned to the same axes?

Parts are always rectangles, the checks shall always be done for the X and Z axes. Y does not get involved at all.

Cool. Two more Qs:

  1. What are you using this for? Just in case there’s an easier way to accomplish it.

  2. How fast does this need to be? Are you running it once as a setup step on an unchanging map? Or for every single part every single frame?

I have a huge map of the world, made up of ~32,000 rectangular parts. I need to check whether a part has “sea access” (the issue that I’m dealing with right now) and assign a boolean value at the server setup - once.

Those yellow dots are 1x1 studs for reference.

Ah I see! And is this map hand-created? Or are you generating it when the server starts as well?

It is hand-made. No generation is involved.

Hey @xVlado, I suggest using diagonal raycasts so you can check for empty spaces diagonally, combined with the current X and Z checks (45 degrees),

Can you try it and reply me your result? Thanks :smile:

1 Like