How can I get the surrounding?

I’m looking for a way to take note of which Parts are in the surrounding area of the door.

As shown in the image below, I’m looking to keep note of what is:

  • Behind
  • Left
  • Right

of the Door. Ignoring anything in front.

What are some ways I can do this? I was thinking I could use RayCast along the RightVector and Inverse LookVector to take note of parts around it? But not sure how effective that’d be.

1 Like

You could use raycasting but I suggest against that. If you were casting from, say the left right and front of the door you’d only be able to cast in a line unless you scripted a function that casted multiple times from the center to the desired destination.

I’d suggest using region3 if you wanted to do this. It basically takes 2 sets of Vector3 values and creates a box from them, logging everything inside into a table.
Region3 (roblox.com)

5 Likes

Oooh, I never even thought about R3.

So, Hypothetically, I could create a box surrounding the Door and call on R3 to take note of any parts in the surrounding?

1 Like

Pretty much. To take it one step further you could take note of the position of the door and the position of objects inside the R3 and then deduce which direction it is from the door, choosing whether or not to ignore it.

1 Like

What’s the use case? If you can get away with instead checking a select few parts that may be relevant then that’s almost certainly going to be easier/more robust/faster.

1 Like

Okii - So trialing this I’ve ran into the issue:

Region3 only seems to locate Parts in Workspace - The room itself will be a ViewportFrame as it’s the areas around the door that won’t need to render.