Hello!
I’m working on this wall system, however I have run into an issue where the wall extends if the window/doorframe is half off of the wall:
How do I fix this?
Thing that constructs the new wall:
local function makeCutout(wallPart: BasePart, window: Model)
local boundingBox = window.PrimaryPart :: BasePart
local windowRelativeToWall = wallPart.Parent.WorldPivot:PointToObjectSpace(boundingBox.Position)
local wallPartRelativeToWall = wallPart.Parent.WorldPivot:PointToObjectSpace(wallPart.Position)
local windowTop = windowRelativeToWall.Y + (boundingBox.Size.Y / 2)
local wallPartTop = wallPart.Size.Y / 2
if windowTop < wallPartTop then
local topSize = wallPartTop - windowTop
local topPart = wallPart:Clone()
local newPart = Instance.new('BoolValue')
newPart.Parent = topPart
newPart.Name = 'NewPart'
newPart.Value = true
collectionService:AddTag(topPart, 'WallPart')
topPart.Name = 'WallPart'
topPart.Parent = wallPart.Parent
topPart.Transparency = 0
topPart.Size = Vector3.new(boundingBox.Size.X, topSize, topPart.Size.Z)
topPart.Position = wallPart.Parent.WorldPivot:PointToWorldSpace(
Vector3.new(windowRelativeToWall.X,
windowTop + topSize / 2,
wallPartRelativeToWall.Z
)
)
end
local windowLeft = windowRelativeToWall.X - boundingBox.Size.X / 2
local wallLeft = wallPartRelativeToWall.X - wallPart.Size.X / 2
if windowLeft > wallLeft then
local leftPart = wallPart:Clone()
leftPart.Transparency = 0
local leftSize = windowLeft - wallLeft
local newPart = Instance.new('BoolValue')
newPart.Parent = leftPart
newPart.Value = true
newPart.Name = 'NewPart'
collectionService:AddTag(leftPart, 'WallPart')
leftPart.Name = 'WallPart'
leftPart.Parent = wallPart.Parent
leftPart.Size = Vector3.new(leftSize, leftPart.Size.Y, leftPart.Size.Z)
leftPart.Position = wallPart.Parent.WorldPivot:PointToWorldSpace(
Vector3.new(
windowLeft - leftSize / 2,
wallPartRelativeToWall.Y,
wallPartRelativeToWall.Z
)
)
end
local windowRight = windowRelativeToWall.X + boundingBox.Size.X / 2
local wallRight = wallPartRelativeToWall.X + wallPart.Size.X / 2
if windowRight < wallRight then
local rightPart = wallPart:Clone()
rightPart.Transparency = 0
local rightSize = wallRight - windowRight
local newPart = Instance.new('BoolValue')
newPart.Parent = rightPart
newPart.Value = true
newPart.Name = 'NewPart'
collectionService:AddTag(rightPart, 'WallPart')
rightPart.Name = 'WallPart'
rightPart.Parent = wallPart.Parent
rightPart.Size = Vector3.new(rightSize, rightPart.Size.Y, rightPart.Size.Z)
rightPart.Position = wallPart.Parent.WorldPivot:PointToWorldSpace(
Vector3.new(
windowRight + rightSize / 2,
wallPartRelativeToWall.Y,
wallPartRelativeToWall.Z
)
)
end
if wallPart.Name == 'WallPart' then
wallPart:Destroy()
end
end