I have this code which breaks parts welds if they hit something too fast but for some reason, the whole model breaks from one impact.
Video:
Code:
local model = script.Parent
local Parts = model:WaitForChild("Parts")
local strength = 3
local function OnTouched(part, hit)
local partMass = part.AssemblyMass
local hitMass = if hit.AssemblyMass == math.huge then 0 else hit.AssemblyMass
local partVelocity = part.AssemblyLinearVelocity * partMass
local hitVelocity = hit.AssemblyLinearVelocity * hitMass
local relativeVelocity = partVelocity - hitVelocity
local force = relativeVelocity.Magnitude
local forceThreshold = partMass * strength
if force >= forceThreshold then
part:BreakJoints()
end
end
for i,v in ipairs(Parts:GetChildren()) do
if v:IsA("BasePart") then
v.Touched:Connect(function(hit)
OnTouched(v, hit)
end)
end
end
Not a scripter, but if I had to take a guess Iâd say itâs because the force that breaks one weld also passes through the part itself which in turn breaks the next weld and so on, and so on.
Try making it so the parts within the model canât break the welds of other parts inside the model.
In case the edit doesnât show on my other comment Iâll also type it as a reply:
Try making it so the parts within the model canât break the welds of other parts inside that model (i.e. an extra if statement that checks if the part is parented to the same model). It might come with its own challenges such as not breaking enough on impact, but I think it would depend on the purpose of the script.
Definitely try making the script check the parent of the part that hits the model, that way parts inside the model itself donât affect each other. Hope this helps.
I think your script works the way you want it to. The method youâre using to impact the object applies it over the entire object. Try dropping it onto something smaller to see if it works.
If this doesnât work, then donât make it 100% guaranteed to break the weld â instead, give it like a 20% chance to break each weld, that way itâs impossible for all welds to break at once.
I donât think itâs that. The problem is, all parts are moving at the same velocity as one another â and Iâm assuming they all have the same mass. Since they all have the same velocity and same mass, theyâll hit with the same force.
Iâm not quite sure what youâre wanting to happen. What is the ideal way you want the object to break apart? Unless you add some sort of randomness or variety to your script/parts, they will all continue to do the same thing as one another unless the area of impact is smaller than the object itself.
After parts break, their assembly mass decreases because they arenât connected to any other parts so it goes back to its own mass. All I want is parts to break on impact but this isnât what I like.
Right there â âAfter parts breakâ This happens only after the parts break. However, at the moment of impact, all parts break instantaneously, meaning this doesnât affect anything. What youâre thinking would work in real life since reality doesnât need to take the time to calculate its physics and the bonds holding materials together are elastic.
In roblox, welds are not elastic at all, thus there is no âshockwaveâ travelling through the object, and any force applied to the object is applied to all constituent parts simultaneously.