I’m trying to make a game and I need a destruction physics system almost exactly like the destruction physics used in this game 💥 Destruction Simulator - Roblox
Does anyone know how this is done?
I’m trying to make a game and I need a destruction physics system almost exactly like the destruction physics used in this game 💥 Destruction Simulator - Roblox
Does anyone know how this is done?
Explosion instances are an easy way to add explosions into your game:
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- damages terrain
explosion.Parent = workspace
you can find their docs here: Explosion | Documentation - Roblox Creator Hub
additionally, you can set a position and use Debris service to get rid of the parts after they’ve been exploded:
local Debris = game:GetService("Debris")
local partDestroyTimer = 3
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- damages terrain
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace
local function partHit(hit: BasePart, dist: number)
Debris.AddItem(hit, partDestroyTimer)
end
explosion.Hit:Connect(partHit)
debrisservice docs: Debris | Documentation - Roblox Creator Hub
these code samples are samples and may not work perfectly; they’re just examples
Do you think this game used WeldConstraints and broke them upon collision?
yes, most likely – i saw in your recent posts that you used anchored parts, which may not work as well. If you need to weld many parts at the same time, Roblox Studio has a built-in function that you can use if you go to the tab where you can create constraints. you can select a group of parts, and click on the WeldConstraints button to automatically weld a group of parts
there’s also plugins that automatically weld parts for you
Okay perfect. I made a script that I think should work.
Do you see any flaws?
local projectile = script.Parent
-- // This function runs second!
local function CollateralDamage(parts)
for i, v in pairs(parts) do
v.BrickColor = BrickColor.new("Cyan")
local instances = parts:GetDescendants()
for _, weld in pairs(instances) do
local chance = math.random(1, 2)
if weld.ClassName == "WeldConstraint" and chance == 1 then
weld:Destroy()
end
end
end
end
-- // This function runs first!
local function DamageStructure(hit)
hit.BrickColor = BrickColor.new("Really red")
local instances = hit:GetDescendants()
for i, v in pairs(instances) do
if v.ClassName == "WeldConstraint" then
v:Destroy()
local touchingParts = hit:GetTouchingParts()
CollateralDamage(touchingParts)
end
end
end
-- // Detect when projectile has come in contact with a part
projectile.Touched:Connect(function(hit)
DamageStructure(hit)
end)
Also something I’ve been wondering for a while, is there a difference between using
for _, v in pairs()
and
for i, v in pairs()
And is the pairs()
portion necessary?
The only difference is that when using the underscore, you won’t be able to get the index. So you won’t know the “i”
Oh, I completely misunderstood what you said regarding the explosion instance. That’s exactly what I was looking for! I must’ve accidently skimmed over it the first time I read your reply. Thank you, that’s the solution!
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.