# How do i check if a position is within/fits inside a block/Region3?

The title says it all, I already have a position and the block, just need a way check if the position is inside the block.

The best I could do was to try to use `Region3:FindPartsInRegion()`, but it didn’t work for me. Here’s the code for the region3 script I tried to use:

``````local pos = Vector3.new(0,1,0) -- not the actual position
local region = GetFromRegionsTable(regionName)
local parts = game:GetService("Workspace"):FindPartsInRegion3(region)

for _,part in pairs(parts) do
if part.pos == pos then
print("Found part inside region!")
break
end
end
``````

Is there a better way to do this?

3 Likes

Well, you won’t be able to accomplish this that way, comparing CFrames directly won’t be of help since you’ll have to account for not only position, but rotation, and what are the chances of parts in there matching the position and rotation?

I am not sure how you make your Region3’s but you could try raycasting to see if you hit any parts inside the region.

Oh. Is there a way to check if a position is within a block/Region3?

Sorry, I think i may have mixed up Cframes with Positions

I have a method of determining if a position is inside a brick using from a previous post:

It uses inverse CFrame so the block’s rotation is taken into account.

4 Likes

Here’s a slightly modified code snippet I use from some post on some thread by Davidii

``````local function partIntersectsPoint(part, point, shape)
local delta = part.CFrame:pointToObjectSpace(point)
delta = Vector3new(abs(delta.X), abs(delta.Y), abs(delta.Z))
local halfSize = part.Size / 2

if shape == Enum.PartType.Block then
local inX = delta.X <= halfSize.X
local inY = delta.Y <= halfSize.Y
local inZ = delta.Z <= halfSize.Z

return inX and inY and inZ
elseif shape == Enum.PartType.Ball then
local inR = delta.magnitude <= halfSize.X

return inR
end
end
``````

works for blocks and balls, and pretty easy to adapt it to cylinders or wedges.

1 Like