So basically this is rather simple.
Lets say we have a part (green part)
Now lets say this part was inside of another part:
now its obscured.
But if it was like this:
it isnt obscured , as its still out in the open.
How can I detect this?
So basically this is rather simple.
Lets say we have a part (green part)
How can I detect this?
Honestly this is more straight forward just use workspace:GetPartsInPart()
along with overlap params
By itself I cant really do anything with GetPartsInPart().
For instance using GetPartsInParts(), in this example:
I wrote this, let me know if this works.
function CheckObscurity(MainPart : BasePart, SmallerPart : BasePart)
local smallerPartSize = SmallerPart.Size
local mainPartCFrame = MainPart.CFrame
local smallerPartCFrame = SmallerPart.CFrame
local corners = {
Vector3.new(-0.5, -0.5, -0.5),
Vector3.new(-0.5, -0.5, 0.5),
Vector3.new(-0.5, 0.5, -0.5),
Vector3.new(-0.5, 0.5, 0.5),
Vector3.new(0.5, -0.5, -0.5),
Vector3.new(0.5, -0.5, 0.5),
Vector3.new(0.5, 0.5, -0.5),
Vector3.new(0.5, 0.5, 0.5)
}
for _, cornerOffset in ipairs(corners) do
local worldCorner = smallerPartCFrame:PointToWorldSpace(cornerOffset * smallerPartSize)
local localPoint = mainPartCFrame:PointToObjectSpace(worldCorner)
local halfSize = MainPart.Size / 2
if math.abs(localPoint.X) > halfSize.X or
math.abs(localPoint.Y) > halfSize.Y or
math.abs(localPoint.Z) > halfSize.Z then
return false
end
end
return true
end
local result = CheckObscurity(workspace.MainPart, workspace.SmallPart)
if result then
print("Is obscured")
else
print("Not obscured")
end
You can use a different method called workspace:ArePartsTouchingOthers()
though I don’t know why you need to check obsecurity of a part
This was the approach I was considering, my only concern is that the MainPart could be covered by multiple parts, or multiple parts could be covering the corners, if I cant find anything else I will definattly use this solution.
I dont think I can use this to check if its fully obscured, as with this sure I can tell if the part is touching another part, but that really doesnt help much in the grand scheme of things.
Im working on a plugin, and this would help a lot with it :]