Does anyone have any alternative to region3?

I’m making a base builder that requires region3 to check for colliding parts (to stop you building bricks on top of one another).
Annoyingly, however, region3 does not respect rotation and it cannot be rotated.

Does anyone have an idea of how better I can do this? The video below shows the issue. The build part is red, region3 is green.

2 Likes

This video is unavailable.
Anyway, this might be what you’re looking for.

1 Like

Whoops, fixed the video, I’ll give that a look now, thank you

Still waiting for the video, but in the meanwhile:

Region3 is nice when you want to get a bunch of -somethings-

If you already know what positions you need to check (raycast to get nearby parts or something) then you could use something like this I made a while ago

This should get you started in the right direction if something like this is what you need

local Vector3_new = Vector3.new
local CFrame_new = CFrame.new

local CFrame_origin = CFrame_new()
local Vector3_origin = Vector3_new()

local math_abs = math.abs
local function invokeVector(vector, func)
	return Vector3_new(func(vector.X), func(vector.Y), func(vector.Z))
end

local function getOffset(region, position)
	local offset = (region.CFrame):pointToObjectSpace(position)
	offset = invokeVector(offset, math_abs)
	return offset
end

local function isInRegion(region, position)
	local extents = region.Size / 2

	local offset = getOffset(region, position)
	return offset.X < extents.X and offset.Y < extents.Y and offset.Z < extents.Z
end

--main
-- regionTable can take:
--	Size
--	CFrame
--	Padding
-- pass in regionTable.Object = <basePart> and itll autofill Size and CFrame
return function(regionTable, targetPosition)
	--construct
	--use Object first, the following properties become overrides
	local passedObject = regionTable.Object
	if passedObject and passedObject:IsA("BasePart") then
		regionTable.Size = passedObject.Size
		regionTable.CFrame = passedObject.CFrame
	else
		warn("(RegionCheck) Passed Object is not a BasePart!")
	end
	local size = regionTable.Size or Vector3_origin
	local cframe = regionTable.CFrame or CFrame_origin
	local padding = regionTable.Padding or Vector3_origin

	regionTable.CFrame = cframe
	regionTable.Size = size + padding

	local success = isInRegion(regionTable, targetPosition)
	--if DEBUG is true, draw a box in our region
	if DEBUG then
		local BoxHandleAdornment = Instance.new("BoxHandleAdornment", workspace.Terrain)
		BoxHandleAdornment.Color = success and BrickColor.new("Bright blue") or BrickColor.new("Bright red")
		BoxHandleAdornment.Transparency = 0.8
		BoxHandleAdornment.CFrame = regionTable.CFrame
		BoxHandleAdornment.Size = regionTable.Size
		BoxHandleAdornment.Adornee = workspace.Terrain
		game.Debris:AddItem(BoxHandleAdornment, regionTable.DebugLifetime or 0.03)
	end
	return success
end
4 Likes

I believe @EgoMoose made a rotated region3 module.
edit: found the wiki article.

2 Likes

Could you try using GetToucingParts (http://wiki.roblox.com/index.php?title=API:Class/BasePart/GetTouchingParts) using the same principle that Quenty described here?

2 Likes

Yep! Here’s some code!

1 Like

Thanks for the help guys, got it working now!

1 Like

In restaurant tycoon I used part:GetTouchingParts()

but just with invisible bounding boxes under the map, and no fancy code

It’s probably not as efficient🤔