How to create in game brick cutter?

How to create in game brick cutter? So I saw this post a few years ago in Headless Developers and I have been mystified ever since. It was basically where this dude held down his mouse and made like a line and kept doing it to a brick and kept cutting it, like a sword and a ninja and a melon.


Like this how do I do the math and calculations for this? I mean it’s really cool, but could I even do this on a 3d scale? Let’s say that, but we can do it with 3d corner wedges and stuff, how would I do it?

1 Like

I mean, theirs a plugin for this lol.

1 Like

He said in-game. Sort of like fruit ninja. Is this what BloxFruit Is? Never played it.

1 Like

Well, how it works not that complicated as you make it seem. Wherever your mouse is located, there will be a negate block that spawns and it will negate the part. However, I have never don’t this before, and I am not sure how complicated scripting it will be.

Although that is possible, the outcome won’t be what he will expect it to be. Unless I just don’t know unions alot, to my knowledge negating a part doesn’t make them complete seperate parts, just a union with a certain area of it vanished.

Correct me if i’m wrong though.

You are correct, but it would be a lot of effort to make something like that a geometric part.

This video might be what your looking for
(By B Ricey) So I decided to slice bread in Roblox Studio ... (with scripts) - YouTube

I actually dont think this process is THAT complicated. But I’m a complete newb to roblox so bear with me here.

Step 1: Create a Part.
Step 2: Create a Plane which divides that part. (In the 2d example above it’s a line, but in 3d it would be a plane.
Step 3: If a Plane were to “divide” a Part, create a duplicate of that same part at the same position.
Step 4: Negate all Part material on one side of the plane for one of the parts by creating an appropriately sized Negative Part and unioning it with the first part. Do the same for the other side of the plane and the second part.
Step 5: Viola! You have “cut” a part into two new parts.

Untitled

Yeah but how do I make it 3d like in this game? Who ate my spaghet - Roblox
Edit: Okay I think I can apply the same thing you told me negating one side of the slice and the other side two times for one part
Edit 2: But then how do I figure out the size of the slice, and how do I make it a swipe instead of a click, so you could slice multiple parts at once if the slice intersects with the end points of the (thing)
If you know what I’m talking about

This has been done before and is also easier in concept than you think it is. What you want to use is the BasePart:SubtractAsync function. This will remove any parts passed to it and return a part that is a union with the removed parts. The steps to creating might be as follows, unless you have an alternate method:

  1. Get the part that you want to cut
  2. Get the position where you want to cut the part. You will most likely be using UserInputService or Mouse.Hit.
  3. Get the position on the part in object space you want to cut the part. This can be done using CFrame:PointToObjectSpace or if you wanted the CFrame, CFrame:ToObjectSpace.
  4. Get the two halves of the part from the plane you create from the position where you want to cut. This can be seen as this:
    Screen Shot 2021-06-02 at 7.48.30 AM
    The white ball is the position you want to cut the part at, the red part is the plane you want to cut the part on, and the block is obviously the part you want to split in half. You can get the two halves from the plane like so:
    Halve 1:
    Screen Shot 2021-06-02 at 7.51.51 AM
    Halve 2:
    Screen Shot 2021-06-02 at 7.52.41 AM
    The parts that aren’t covered by the red are the two halves. This means you would call BasePart:SubtractAsync twice to get the two seperate halves.
  5. Parent the two halves to whatever the parent of the original block is.
  6. Call Instance:Destroy on the old block.
1 Like

Can you answer my question that is above your post

Yes. I am working on an example right now, mostly because I wanted to make this for awhile but never actually did. To size the negation part I just use:

cutPart.Size = part.Size * part.Size.Magnitude

with the part variable as the part we want to cut. While you can create a version that follows your swipe it would most likely be expensive and because of human error, not straight. It’d be best to either have a start and end point (the position of the click when you started and the position of the click when you ended) and then cut along that line.

Also, I’m currently making an all-in-one function for this.

Can you play the game that I linked if you cut a block from the corner it will be like a diamong shape if you cut a cylinder or a ball it will be a circle shape how is this possible

I just looked at it. The way it works is that it gets the relative direction of the player’s Camera | Roblox Creator Documentation to the position where they want to cut to get relative direction and therefore the axis to cut from.

Snack Break Problem #28 - Scripting Helpers Thank goodness my recollection of this post popped up in my brain, here is a good solution by EgoMoose

Alright, I finally created solution using in-game CSG. However, like @greatneil80 mentioned, there is another way you can do this. It doesn’t use CSG but it does instance and create a bunch of new parts, so it depends on the situation you’re using this for if you want performance.

Anyways, here’s my solution that uses CSG:

local params : RaycastParams = RaycastParams.new() -- Our raycast parameters
params.FilterType = Enum.RaycastFilterType.Whitelist
params.IgnoreWater = true

-- Cuts the part in half
local function Cut(part : BasePart, axis : CFrame) : ()
	params.FilterDescendantsInstances = {part}
	
	-- The relative location of part to axis
	local relativeVector = (axis.Position - part.Position)

	-- Get the lookVector of the axis
	local lookVector : Vector3
	if axis.RightVector:Dot(relativeVector.Unit) > 0 then -- Sets the lookVector to go towards the part we want to cut
		lookVector = -axis.RightVector
	else
		lookVector = axis.RightVector
	end
	
	-- Check if the axis intersects the part and cuts it if it does
	if workspace:Raycast(axis.Position, axis.Position + (lookVector * relativeVector.Magnitude), params) or workspace:Raycast(axis.Position - (lookVector * relativeVector.Magnitude * part.Size.Magnitude), axis.Position, params) then  -- Checks to see if we are touching or hit the part
		-- Create the part we will use to "cut" the part across the axis
		local cutPlane : Part = Instance.new("Part")
		cutPlane.Anchored = true
		cutPlane.Size = part.Size * part.Size.Magnitude
		cutPlane.CFrame = axis + (lookVector * cutPlane.Size.Z * 0.5) + (axis.LookVector * cutPlane.Size.Z * 0.5)

		-- Creates and Parents the halves
		part:SubtractAsync({cutPlane}).Parent = part.Parent
		cutPlane.CFrame -= (axis.LookVector * cutPlane.Size.Z)
		part:SubtractAsync({cutPlane}).Parent = part.Parent

		-- Destroy unneeded parts
		part:Destroy() -- The original part
		cutPlane:Destroy() -- The negation part
	end
end

I’ve set up an example here:

1 Like

The slice you’re going to have to calculate on your own from click point to point release. As I’m new to roblox I’m not certain what API functions are available for transforming 2d/3d screen space interactions. My example assumes you’re already figured out how to make your line.

As for your question about 2d to 3d… My example IS a 3d example. It’s just a 2d representation, it would work just the same from every angle you cut it at no problem. As for the size of the negation part there’s a few different ways you can do this. The easiest is just make the size of the part a full order of magnitude larger than the original part. If the first part is between 110^1 and 110^2 then make it between 110^3 and 110^4. This is a sloppy method but will work a good 99.99% of the time.

Most other ways to do this involve some pretty advanced calculations on where exactly each vertex of the shape you are cutting lies. You have to make sure that all relevant vertices that are on the half of the part that is being negated lies within the region3 of the negation area. You could also solve this problem using a BSP but again, I don’t think it’s necessary.