function CreateRegion3FromLocAndSize(Position, Size)
local SizeOffset = Size/2
local Point1 = Position - SizeOffset
local Point2 = Position + SizeOffset
return Region3.new(Point1, Point2)
end
function isTakingSpace(pos,part)
local whitelist = {part}
local region3 = CreateRegion3FromLocAndSize(pos,Vector3.new(1,1,1))
local parts = workspace:FindPartsInRegion3WithWhiteList(region3,whitelist,10)
--print(unpack(parts))
for i,v in pairs(parts) do
if v==part then
return true
end
end
return false
end
This is the idea:
You pass in a Vector3 position and a MeshPart/Union
It returns true if the position is being obstructed in a 1x1 space by the MeshPart/Union
Otherwise, it returns false
Alright so i tested this and it seemed to work fine for me, are you sure that when testing your function the position wasn’t the position of the part?
Also as an alternative to using region’s using this function might be better:
Edit:(Cleaned it up a bit)
local function IsWithinObject(Object, Position)
local Offset = 0
local min, max = Object.Position.X - (Object.Size.X + Offset)/2, Object.Position.X + (Object.Size.X + Offset)/2
local minZ, maxZ = Object.Position.Z - (Object.Size.Z + Offset)/2 , Object.Position.Z +(Object.Size.Z + Offset)/2
local minY, maxY = Object.Position.Y - (Object.Size.Y + Offset)/2, Object.Position.Y +(Object.Size.Y + Offset)/2
if math.clamp(Position.X, min, max) ~= (min and max )and math.clamp(Position.Z, minZ, maxZ) ~=(minZ and maxZ) and math.clamp(Position.Y, minY, maxY) ~=(minY and maxY) then
return true
else
return false
end
end
local function GetTouchingParts(part)
local connection = part.Touched:Connect(function() end)
local results = part:GetTouchingParts()
connection:Disconnect()
return results
end
function isTakingSpace(pos,part)
local checkPart = Instance.new('Part',part.Parent)
checkPart.Size = Vector3.new(.1,.1,.1)
checkPart.Anchored = true
checkPart.CFrame = CFrame.new(pos)
local touching = GetTouchingParts(checkPart)
for i,v in pairs(touching) do
if v == part then
checkPart:Destroy()
return true
end
end
checkPart:Destroy()
return false
end
Also, if you’re wondering why I’m using a seemingly redundant function to GetTouchingParts, check out this post: