Explosion

Pokaż przestarzałe

*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.

Wybuch zastosuje siłę do BaseParts wewnątrz wybuchu BlastRadius.Siła ta łamie JointInstances i WeldConstraints między częściami i zabija Humanoid postacie nie chronione przez ForceField .Constraints nie zostanie zniszczony przez eksplozję.

Jeśli Explosion jest powiązany w dowolnym miejscu modelu danych podczas uruchamiania doświadczenia, natychmiast się uruchamia i w ciągu kilku sekund staje się niepowiązany.Nie jest zniszczony za pomocą Instance:Destroy() w tym przypadku, więc połączenia nie są odłączane, a rodzic nie jest zamykany.Podobnie jak w przypadku wszystkich instancji, utrzymanie silnego odniesienia an Explosion uniemożliwi jego gromadzenie odpadów.

Zauważ, że Explosion musi być potomkiem Workspace dla wizualizacji eksplozji, aby grały i miały wpływ fizyczne/uszkadzające efekty.

Efekty wybuchu

Humanoids zostają zabite przez eksplozje, ponieważ eksplozja łamie łącze szyi znaku Model.Wychowanie ForceField do modelu ochroni wszystkie jego dzieci przed efektem zabójstwa wybuchu.

Jeśli nie chcesz, aby połączenia między BaseParts były złamane lub chcesz wdrożyć własną formułę uszkodzenia Humanoids, zaleca się ustawienie DestroyJointRadiusPercent na 0 i wykorzystanie wydarzenia Hit do obsługi wyniku wybuchu.

Wybuchy mogą być również skonfigurowane, aby zadać obrażenia Terrain, tworząc kratery, jak skonfigurowano za pomocą właściwości ExplosionType.

Zauważ, że efekt wybuchu nie jest zakłócony przez przeszkody , co oznacza, że części/tereny osłonięte za innymi częściami/terenami nadal będą dotknięte.

Przykłady kodu

Ten przykład kodu zawiera krótki fragment, który tworzy dużą eksplozję w grze na 0, 10, 0.

Natychmiastowa eksplozja

local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- szkodzi terenowi
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace

Podsumowanie

Właściwości

Zdarzenia

Właściwości

BlastPressure

Odczyt równoległy

Przykłady kodu

Custom Explosion

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
-- Roblox removes explosions after a few seconds, but does not destroy them.
-- To ensure our .Hit connection gets disconnected, destroy the explosion once it's removed.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)

BlastRadius

Odczyt równoległy

Przykłady kodu

Natychmiastowa eksplozja

local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- szkodzi terenowi
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace

DestroyJointRadiusPercent

Odczyt równoległy

Przykłady kodu

Non lethal explosions

local function onDescendantAdded(instance)
if instance:IsA("Explosion") then
local explosion = instance
explosion.DestroyJointRadiusPercent = 0
local destroyJointRadiusPercent = 1
explosion.Hit:Connect(function(part, distance)
-- check the part is in range to break joints
if distance <= destroyJointRadiusPercent * explosion.BlastRadius then
-- make sure the part does not belong to a character
if not game.Players:GetPlayerFromCharacter(part.Parent) then
part:BreakJoints()
end
end
end)
end
end
workspace.DescendantAdded:Connect(onDescendantAdded)
Custom Explosion

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
-- Roblox removes explosions after a few seconds, but does not destroy them.
-- To ensure our .Hit connection gets disconnected, destroy the explosion once it's removed.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)

ExplosionType

Odczyt równoległy

Przykłady kodu

Zatrzymaj wybuchy przed zniszczeniem terenu

local function onDescendantAdded(instance)
if instance:IsA("Explosion") then
instance.ExplosionType = Enum.ExplosionType.NoCraters
instance:GetPropertyChangedSignal("ExplosionType"):Connect(function()
instance.ExplosionType = Enum.ExplosionType.NoCraters
end)
end
end
workspace.DescendantAdded:Connect(onDescendantAdded)

LocalTransparencyModifier

Ukryte
Bez replikacji
Odczyt równoległy

Position

Odczyt równoległy

Przykłady kodu

Natychmiastowa eksplozja

local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- szkodzi terenowi
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace

TimeScale

Odczyt równoległy

Visible

Odczyt równoległy

Przykłady kodu

Explosion Custom Visuals

local function customExplosion(position)
local explosion = Instance.new("Explosion")
explosion.Position = position
explosion.Visible = false
local attachment = Instance.new("Attachment")
attachment.Position = position
attachment.Parent = workspace.Terrain
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Enabled = false
particleEmitter.Parent = attachment
particleEmitter.Speed = NumberRange.new(5, 30)
particleEmitter.SpreadAngle = Vector2.new(-90, 90)
explosion.Parent = workspace
particleEmitter:Emit(20)
task.delay(5, function()
if attachment then
attachment:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0))

Metody

Zdarzenia

Hit

Parametry

part: BasePart
distance: number

Przykłady kodu

Custom Explosion

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
-- Roblox removes explosions after a few seconds, but does not destroy them.
-- To ensure our .Hit connection gets disconnected, destroy the explosion once it's removed.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)