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.
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