Hello, I am currently working on a breakable glass system and I had this idea on how to make but I need a bit of information before jumping into coding it. (the system is utilizing fortunes algo to detect where the wedges would be)
What I’m facing is that I don’t know how I can implement it into lua and go about getting points on a parts to utilize the algorithm,
If there’s any solution/idea I would love to hear it!
It’s not very clear what you are trying to do. But if you are trying to position parts you should use the parts CFrame which contains the position and rotation of a part.
In Fortunes algorithm you would have points that would calculate the distance between them and fill the area between those pixel points
I am saying how I can do this in a 3D workspace unlike the 2D workspace shown in the image.
I’m not sure what you mean by “fill” but if you want to draw a line between 2 points you can do
local middlePoint = part1.CFrame:Lerp(part2.CFrame,0.5) -- using :Lerp to get the middle point between the parts
local length = (part1.Position - part2.Position).Magnitude -- using subtraction to get the length
linePart.CFrame = CFrame.lookAt(middlePoint,part2.CFrame.Position) -- using CFrame.lookAt so it has the correct orientation
linePart.Size = Vector3.new(1,1,length) -- setting the size to "length" on the z axis
if there are multiple points you can make multiple lines
“filling” a 3d space is much more complicated and would require a lot of resizing of parts and triangles and stuff.
The points you’re talking about are chosen arbitrarily, you need to generate them yourself randomly by treating the face of the part that you’re trying to break as a plane. Just pick a face and go to town!
Here’s an example for the top or bottom face of a part.
local points = {}
for i = 1, 10 do -- make 10 points
points[i] = Vector3.new(
Part.Size.X * math.random(),
0, -- doesn't matter what the Y value is, we only care about 2 dimensions
Part.Size.Z * math.random())
end
Now you run Fortune’s algorithm on the points table.