Hello, I’m trying to create blast resistance, like in Minecraft. Basically, every block should have a blast resistance property that reduces explosion damage to blocks behind it based on the blast resistance level.
I’ve tried using the Minecraft wiki but I don’t understand it: Explosion – Minecraft Wiki (fandom.com)
It would be great if anyone could help me!
1 Like
Sounds like you might have to use raycasting or create a custom blast explosion to find the parts hit. (In the custom explosion it will do no damage)
from the wiki:
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 -- this could be set higher to still apply velocity to parts
explosion.DestroyJointRadiusPercent = 0 -- joints are safe
explosion.BlastRadius = radius
explosion.Position = position
-- set up a table to track the models hit
local modelsHit = {}
-- listen for contact
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- check to see if this model has already been hit
if modelsHit[parentModel] then
return
end
-- log this model as hit
modelsHit[parentModel] = true
-- look for a humanoid
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- get the distance as a value between 0 and 1
distanceFactor = 1 - distanceFactor -- flip the amount, so that lower == closer == more damage
humanoid:TakeDamage(maxDamage * distanceFactor) -- TakeDamage to respect ForceFields
end
end
end)
explosion.Parent = game.Workspace
end
You can edit that code to do specific damage to players or parts based on the different types of resistances that were hit near a player.
1 Like