Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
COMMUNITY QUESTION

How can I cut a brick in half?

1 answer

##How is it possible?

You could make an effect that looks like you're cutting the brick in half by creating two identical half parts, placing them on either side of the original part, then simply destroying the original part.

###What do you need?

Sounds easy, but there's a few things to think about. Such as which axis you're trying to cut in half. You can't cut multiple axis in half otherwise it starts being 4ths. Here's a visual.

For this example, i'll use the x-axis.

Another thing to think about, is how to position the two parts on either side of the original brick. Position comes from the origin of the part; the middle. You need to find a place that is 1/4th of the part's size(on that axis) away from the origin of the part. Here's a visual of why this is makes sense.

##Code

function CutPart(orig)
	--Gather the extents of the new parts
	--Cut the x axis
	local extentsX,extentsZ,extentsY = orig.Size.X/2,orig.Size.Y,orig.Size.Z;
	--Define the origin
	local pos = orig.CFrame;
	for i = 1,2 do --For loop for 2 parts
		local new = orig:Clone(); --Clone and cut
		new.Size = Vector3.new(extentsX,extentsY,extentsZ);
		--Account position for each side of the axis you're cutting
		--Divide in half again to get 1/4th size
		local x = (i == 1 and -extentsX/2) or extentsX/2;
		--Move in from the origin
		local newPos = pos * CFrame.new(x,0,0);
		new.CFrame = newPos;
		new.Parent = orig.Parent;
	end
	orig:Destroy(); --Destroy the original part
end

You can now call this function on any part to see it in action.

local p = Instance.new("Part",workspace);
p.Size = Vector3.new(5,5,5);
p.CFrame = CFrame.new(0,10,0);
p.Anchored = true;

wait(2);

CutPart(p);

This discussion is preserved as it was. New answers, comments, and votes are closed.