See if Vector3 is in Region3?

Is there a way I can see if a Vector3 is in a Region3 without creating a new part?

1 Like

Check the coordinates; check if the Vector3’s X is bigger than the lower region3’s X and smaller than the upper region3’s X, same for the other coordinates.

1 Like

Can I get the lower and upper parts of the Region3 from the Region3 itself?

Combine its Size and the Position.

This is what I came up with. Is this what you meant?

	if pos.X > region.Size + region.CFrame.p and pos.X <region.Size - region.CFrame.p then
       --Do stuff
	end

EDIT: I know my code won’t work but I wrote it in like 5 seconds. The concept is what I want.

Define the lower bound as Region3.CFrame.p - (Region3.Size/2), the upper bound as Region3.CFrame.p + (Region3.Size/2) and use those to check the Vector3’s components against.

function isInRegion3(region, point)
    local relative = (point - region.CFrame.p) / region.Size
    return -0.5 <= relative.X and relative.X <= 0.5
       and -0.5 <= relative.Y and relative.Y <= 0.5
       and -0.5 <= relative.Z and relative.Z <= 0.5
end

EDIT: accidentally did a sphere check, this is the box check

18 Likes