Hey, I’m starting a new project based on explosions etc.
and I want to know how to make parts/buildings destructible. Like in Doomspire Brickbattle.
I’ve tried using weld constraints but they don’t seem to be removed when there is an explosion,
also inlets and outlets etc.
Could anyone help me? Thanks! Any help is appreciated.
Sure, I can help you with that!
To make parts/buildings destructible, you can use a combination of different techniques. Here are a few options:
-
- Use the BreakJoints() function:
You can use the BreakJoints() function to break all the WeldConstraints in a given part or model, which will cause the part or model to fall apart. Here’s an example:
-- assume that 'part' is the part you want to make destructible
function makeDestructible(part)
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
part:BreakJoints()
end
end)
end
In this example, we’re using the Touched event to detect when a player touches the part. When a player touches the part, we check to see if their character has a Humanoid. If they do, we break all the WeldConstraints in the part.
-
- Use the Inlet and Outlet:
Another option is to use the Inlet and Outlet properties of a Part. The Inlet and Outlet properties allow you to create a hierarchy of parts that are connected together. When you apply a force to the Inlet, it will propagate through the hierarchy of parts until it reaches the Outlet.
Here’s an example:
-- assume that 'part' is the part you want to make destructible
function makeDestructible(part)
local inlet = Instance.new("Part")
inlet.Anchored = true
inlet.CanCollide = false
inlet.Size = Vector3.new(2, 2, 2)
inlet.Transparency = 1
inlet.CFrame = part.CFrame * CFrame.new(0, -part.Size.Y/2, 0)
local outlet = Instance.new("Part")
outlet.Anchored = true
outlet.CanCollide = false
outlet.Size = Vector3.new(2, 2, 2)
outlet.Transparency = 1
outlet.CFrame = part.CFrame * CFrame.new(0, part.Size.Y/2, 0)
local weld = Instance.new("WeldConstraint")
weld.Part0 = inlet
weld.Part1 = part
weld.Parent = inlet
local inletForce = Instance.new("BodyForce")
inletForce.Force = Vector3.new(0, 1000, 0)
inletForce.Parent = inlet
local outletForce = Instance.new("BodyForce")
outletForce.Force = Vector3.new(0, 1000, 0)
outletForce.Parent = outlet
inlet.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
inletForce.Enabled = false
outletForce.Enabled = true
end
end)
end
In this example, we’re creating an Inlet and Outlet for the part. We’re then creating a BodyForce for each, which will apply a force to the part when we enable the force.
When a player touches the Inlet, we disable the Inlet force and enable the Outlet force. This will cause the force to propagate through the hierarchy of parts until it reaches the Outlet, which will cause the part to break apart.
-
- Use the Destroy() function:
If you want to completely destroy a part when it’s hit by an explosion, you can use the Destroy() function. Here’s an example:
-- assume that 'part' is the part you want to make destructible
function makeDestructible(part)
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
part:Destroy
end
end)
end
To make parts/buildings destructible, you can use the BreakJoints()
method to break any joint constraints that are holding the parts together. This will allow the parts to separate and move independently when they are hit by an explosion or other force.
Here’s an example script that you can use to make a part destructible when it’s hit by a projectile:
local part = -- insert the part you want to make destructible here
local explosionForce = 5000 -- adjust this value to control the force of the explosion
part.Touched:Connect(function(hit)
if hit.Parent:FindFirstChild("Humanoid") then
-- the part was hit by a projectile, break its joints
part:BreakJoints()
-- apply an explosion force to the part
local explosion = Instance.new("Explosion")
explosion.Position = part.Position
explosion.BlastRadius = 10
explosion.Force = explosionForce
explosion.Hit:Connect(function(hitPart)
-- break the joints of any part that was hit by the explosion
hitPart:BreakJoints()
end)
explosion:Fire()
end
end)
This script listens for when the part is touched by another object, and checks if that object has a Humanoid
as its parent. If so, it breaks the joints of the part and applies an explosion force to it. It also creates an Explosion
object that listens for when it hits other parts, and breaks their joints as well.
You can adjust the BlastRadius
and Force
properties of the Explosion
object to control the size and strength of the explosion.
Note that this is just a basic example and you may need to modify it to fit your specific needs, such as detecting different types of collisions or applying more complex destruction effects.
Hey thanks for the ideas, but I want it to work with a gun/rocket launcher.
Kind of like when the bullet of a gun touches a model, all of its parts gets unanchored (or the parts it got hit by the gun)
Any ideas on how to do this? Im thinking raycasting but my brain is too small to do that right now.
Thanks!
If u are using .Touched function for the raycasting then use otherPart to search for the parent. After that, loop through of all otherPart children then filter out what to delete or edit.
Sorry for bumping, maybe it’s too late but if you want to make destructible buildings what you have to do is:
1 - Create a part and set Studs Surface at the top of your Part and Inlet Surface at the bottom of your Part (you can use Plugins to do this)
2 - Build like if you were building with legos: make walls part by part
3 - Put all of the pats in a model which will be your “MainModel”. It doesn’t matter if there are Models inside the MainModel
4 - Insert a Script inside the MainModel which will contain the next script:
script.Parent:MakeJoints()
Here’s a sample building:
SimpleDestructibleBuilding.rbxm (5.8 KB)
This perfectly works with ROBLOX’s classic tools like TimeBomb and Rocket Launcher as what makes the parts break their joints and blow up is the Explosion Instance that these tools creates.
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.