I was testing if I have the needed experience for making like a game, so basically, I wanted to provide the player with a way to make his castle walls, I found a way to link a Part from 2 points in space, but the problem is that I will have units that will try to destroy the wall, but all of it, I want to destroy just a section of it, so how I can make such a system.
Inputs:
Wall (Part), Section (Part).
Output:
returns a model that contains Wall divided by 3, one of them is Section (Part).
So basically I want a function that cut a section from a Part and returns it in a model with the remaining 2 sides (Parts). It works just like “Negate” in the studio but with parts.
You could probably make two copies of the wall, one with Wall being normal and Section negated, and, using this new union, clone it, and negate that from the original Wall again.
This should give two new parts that resemble the Wall perfectly, although the new Wall - Section union will be treated as one part physically. This probably won’t matter for your use case though.
Pseudocode:
function TakeFrom(Wall,Section)
local union = Wall - Section
local newSection = Wall - union
newSection.Anchored = false
Wall:Destroy()
union.Parent = workspace
newSection.Parent = workspace
end
EDIT: Do NOT use this heavily. If you’ve unioned things in studio before, you’ll know it takes quite a bit of time. This is because it’s a complex operation. You should not be sending it rapidly but rather maybe once every 1-5 seconds depending on how complex the part you’re unioning is. (If it’s a simple brick or 2, you can do that more efficiently)
I also need that other Parts, because i will need to resize them from the top surface, but with unions, a lot of other problems will appear, i want them as plain Parts, i’m just lacking the math or at least starting point of implementing such a function !
If you want to use parts for the entire operation, you might as well divide the wall into small sections in the first place instead of having a large model and figuring out how to divide it, and, if you weld/rig the individual parts in each section together, you could just use some sort of .Touched or Region3 function that unanchors the sections of the wall you want.
In this form, you can give individual sections of the wall their own properties, like health or armor, but this can really lock you down on how realistic or emergent your castle wall is. Again, it might not be a problem in your case.
Yeah i thought about that, but it’s not the best solution for such games, because i need maximal performance, so I’m searching for a way to divide just the target part of the wall by the enemy instead of dividing it in the first time, and i don’t need it to be anchored, so when units will hit the wall in some point, I’m going to divide the hited section from the wall and give it health depends on it’s Volume*x , where x is just a value that going to set the material durability, and then the unit can damage it and it’s going to fall down (decreasing the size from the top face) with every set of consumed health, and I know how to do all this on my own, just need to figure out a function that does the parts subtraction
I don’t really think you’re going to find anything more performant. There’s a few options I know of that can complete a task like this but each of them incur their own respective performance cost.
Using runtime unioning
Using runtime fragmentation
When a part is hit, you take that position, then recalculate the part that was hit; from there, you reconstruct it to form a hole in the assembly
Using preassembled fragmentation
Build your part out of many smaller parts and remove the parts that are hit
I personally think the latter is the least costly to performance but at the same time it’s the most restrictive. You’re forced to conform to a certain shape and it may not produce desired results in all cases. It also means that you have more instances involved, which means more memory used up for those parts. It may not be as much initially but it does build up.
Yeah i taught about this 3 ways, and i see that runtime fragmentation going to be better for my situation, but do you know an algorithm for extracting a part section from another?