How can I turn a cube into 4 smaller cubes

I have thought of getting the larger cubes x and y values and z values and dividing them by 2 but how do I position them?

I would get the original position then use the original size values and divide them by two then just make a simple loop and go around placing them in each corner of the original cube.

How do I get the positions of each corner?

Brick cutter plug-in

trying to do this in a script, I’m not building anything

position them using cube.Position = Vector3.new (the position) and to create them use Instance.new ()

There’s probably a better way to do this, but this will work.

local offsets = {
	Vector3.new(-1,-1,-1),	-- bottom forward left
	Vector3.new(1,-1,-1),	-- bottom forward right
	Vector3.new(-1,-1,1),	-- bottom backward left
	Vector3.new(1,-1,1),	-- bottom backward right
	Vector3.new(-1,1,-1),	-- top forward left
	Vector3.new(1,1,-1),	-- top forward right
	Vector3.new(-1,1,1),	-- top backward left
	Vector3.new(1,1,1)		-- top backward right
}

local function subdivideCube(cube)
	for i = 1,8 do -- you can set this to 4 to get the 4 lower cubes, or keep it at 8 for every cube
		local smallerCube = cube:Clone()
		smallerCube.Size = cube.Size/2
		
		local offset = offsets[i] * cube.Size/4
		smallerCube.CFrame = cube.CFrame * CFrame.new(offset)
		
		smallerCube.Parent = cube.Parent
	end
	
	cube:Destroy() -- optional, you might want to keep the original
end

subdivideCube(workspace.Part)
2 Likes

To make a more scalable solution you could do nested for-loops and iterations.

local cubeSize = 1

for i1 = 1, boxwidth do
     for i2 = 1, boxheight do
          for i3 = 1, boxlength do
               local cube = Instance.new("Part")
               cube.Size = Vector3.new(cubeSize, cubeSize, cubeSize)
               cube.Position = Vector3.new(i1, i2, i3) * (cubeSize/2)
                             -- You would want to get the box's size and divide by two, and
                             -- offset each box by that every iteration. In this case it's 1, so
                             -- each box would be offset by 0.5
          end
     end
end

After some additions this should generate a three dimensional cube about the world origin. Changing the cubesize and boxheight, boxlength, boxwidth should change the subdivisions of the cube. If you want it at the position of another cube, you would add that offset Vector3 to each position iteration.

1 Like

Use this equations https://github.com/FrostDracony/Roblox/blob/master/Tutorials/GetCornersOfAllBaseParts/GetCornersOfPart.md

2 Likes