Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
0

How can I cut a brick in half?

Asked by 7 years ago

cutting a brick in half with out getting rid of any pieces

0
What do you mean? Stephenthefox 94 — 7y
0
You can't literally cut the brick in half. You can however create two parts half the size of the initial part and place them side by side to make it appear as though the brick was cut in half. AZDev 590 — 7y

1 answer

Log in to vote
2
Answered by
Goulstem 8144 Badge of Merit Moderation Voter Administrator Community Moderator
7 years ago
Edited 7 years ago

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);
Ad

Answer this question