How would I determine if a part is reachable by another part?

Hello devforum. I want to figure out how one would determine if a part is blocked from reaching another part. The only solution I’ve found was using Roblox’s built-in pathfinding, however ComputeAsync is very, very slow when you account for the fact I need to use this a lot. Raycasting, to my knowledge, also doesn’t work, the reason why is in this diagram:

As you can see, if you cast a direct ray to point b from point a, it will think that the path is blocked, however you can clearly tell that point b is reachable by simply going around the obstacle.

2 Likes

The best way you can use is raycasting, as i know there is no better way than a raycast from the part and check if it hit anything rather than the part you want.

1 Like

But what if point b is FULLY blocked? the ray would think that it’s reachable, as the ray would only be looking for that specific part and nothing else.

1 Like

If your map is 2d, you can easily create a custom pathfinding algorythm!

2 Likes

My map is 3-dimensional.(30charrrss)

2 Likes

Not really, you would check what did the ray hit, if a part with specific name, then its reachable, if no part was hit with this name, then it didnt hit the part we want and it is not reachable.

1 Like

I explained this in the diagram, if the part is blocked from an angle, but reachable from other angles, the ray would have no idea and think the part is blocked.

1 Like

What if you raycast from the part that you want to see if it’s reachable.
Instead of this:

image

You do this:

image

2 Likes

That might work, I’m not too sure just yet though.

3 Likes

You can use raycasts, first of all check magnitude, if it’s bigger then return nil, if it’s OK then create 6 rays and check how many of them hit, if most rays hit then return true

1 Like

Can you elaborate? what should the origin of the 6 rays be? where should they be pointing?

1 Like

Origin should be your part’s A position and 6 directions would be front, back, right, left, down, up

1 Like

Potential Solutions:

  1. Grid-Based Pathfinding (A)*: If you want more control over the speed and accuracy of the pathfinding, you could implement a simplified A* pathfinding algorithm yourself. This would break down the area into a grid and check for reachable spaces without directly relying on ComputeAsync.
  2. Breadth-First Search (BFS): This method could be used in combination with a grid-based approach to check if a point is reachable from another. It’s simpler than A* but might be useful if the environment doesn’t have complicated terrains.
  3. Area of Influence (AOI) Mapping: Another option is to calculate “areas of influence” or “reachability zones” using bounding boxes or spheres around obstacles. By checking overlaps between these zones and the parts, you could simulate a “reachable” check without direct pathfinding calculations every time.
  4. Pre-Processed Path Networks: If the layout doesn’t change often, consider creating a navigation mesh or pre-defined path network in advance. You can then quickly look up paths between two parts based on proximity and avoid the slow real-time pathfinding calculations.
  5. Hybrid Raycasting: Another potential solution is to combine raycasting with iterative steps around the obstacle. For example, cast rays in small angles or directions around the obstacle when a direct path is blocked, simulating how a player or character would “look around” an obstacle to find a clear path.
2 Likes

That’s what i suggested, did it work?

1 Like