[ul]
[li]1st group on the left: The simple y size code + tilted pillar on its side.[/li]
[li]2nd group: The following code taken/edited from qcmdutl. Tilted pillars stack fine![/li]
[li]3rd group: Un-tilted bricks (i.e. the TopSurface points up) work with both your code and qcmdutl the same.[/li]
[/ul]
local NewCFrame = CFrame.new
local bb_points = {
Vector3.new(-1,-1,-1);
Vector3.new( 1,-1,-1);
Vector3.new(-1, 1,-1);
Vector3.new( 1, 1,-1);
Vector3.new(-1,-1, 1);
Vector3.new( 1,-1, 1);
Vector3.new(-1, 1, 1);
Vector3.new( 1, 1, 1);
}
local function RecurseGetBoundingBox(object,sides,parts)
if object:IsA"BasePart" then
local mod = object.Size/2
local rot = object.CFrame
for i = 1,#bb_points do
local point = rot*NewCFrame(mod*bb_points[i]).p
if point.x > sides[1] then sides[1] = point.x end
if point.x < sides[2] then sides[2] = point.x end
if point.y > sides[3] then sides[3] = point.y end
if point.y < sides[4] then sides[4] = point.y end
if point.z > sides[5] then sides[5] = point.z end
if point.z < sides[6] then sides[6] = point.z end
end
if parts then parts[#parts + 1] = object end
end
local children = object:GetChildren()
for i = 1,#children do
RecurseGetBoundingBox(children[i],sides,parts)
end
end
local function GetBoundingBox(objects,return_parts)
local sides = {-math.huge;math.huge;-math.huge;math.huge;-math.huge;math.huge}
local parts
if return_parts then
parts = {}
end
for i = 1,#objects do
RecurseGetBoundingBox(objects[i],sides,parts)
end
return
Vector3.new(sides[1]-sides[2],sides[3]-sides[4],sides[5]-sides[6]),
Vector3.new((sides[1]+sides[2])/2,(sides[3]+sides[4])/2,(sides[5]+sides[6])/2),
parts
end
function copystack(part)
local copy = {}
local copy_parent = {}
for i,v in pairs({part}) do
local o = v:Clone()
copy[i] = o
o.Parent = workspace
--copy_parent[o] = workspace
end
local cSize,cPos,cParts = GetBoundingBox(copy,true)
local selection = {part}
local sSize,sPos
if #selection > 0 then
sSize,sPos = GetBoundingBox({part})
end
local center = CFrame.new(cPos)
local new = CFrame.new(sPos + Vector3.new(0,sSize.y/2 + cSize.y/2,0))
part.CFrame = new:toWorldSpace(center:toObjectSpace(part.CFrame))
end
copystack(workspace.test1)
Weird angled bricks still copy funny even with studio & qcmdutl, but that’s fine. When building a castle/house, most bricks are level.
Even with this, I’m still lacking the important “pop-up” functionality that .Position does with CanCollide bricks when it copies into another brick. Very useful for clone a bunch of bricks into a tall wall, by just clicking the base a bunch of times. Currently my code can’t do that.