I wrote a function to check, but I’m wondering if there’s a better way to check if a part is fully inside another part.
Both the part and hitbox can be in any orientation, position, and size.
For context the function will be run onRenderStepped
function checkInBounds(part, hitbox)
local pointsToCheckInBounds =
{
CFrame.new(-part.Size.X/2,part.Size.Y/2,-part.Size.Z/2),
CFrame.new(part.Size.X/2,-part.Size.Y/2,-part.Size.Z/2),
CFrame.new(part.Size.X/2,part.Size.Y/2,part.Size.Z/2),
CFrame.new(-part.Size.X/2,-part.Size.Y/2,part.Size.Z/2)
}
for i, pointCFrameLocalToPart in pointsToCheckInBounds do
local pointCFrameLocalToHitbox = hitbox.CFrame:ToObjectSpace(part.CFrame:ToWorldSpace(pointCFrameLocalToPart))
if math.abs(pointCFrameLocalToHitbox.X) > hitbox.Size.X/2 or math.abs(pointCFrameLocalToHitbox.Z) > hitbox.Size.Z/2 or math.abs(pointCFrameLocalToHitbox.Y) > hitbox.Size.Y/2 then
return false
end
end
return true
end