Explosion
*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.
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
Używany do określenia ilości siły zastosowanej do BaseParts złapanej w Explosion.BlastRadius.
Właściwość ta określa promień Explosion , w szpilkach.Ten promień określa obszar działania wybuchu, a nie rozmiar wizualizacji wybuchu.
Używany do ustawienia proporcji Explosion.BlastRadius , pomiędzy 0 a 1, w której wszystkie stawy zostaną zniszczone.Wszystko poza tym zakresem będzie miało zastosowaną tylko siłę Explosion .
Właściwość ta określa, w jaki sposób Explosion będzie interakcjonować z Terrain. Używana jest do ustawienia, czy wybuchy spowodują uszkodzenie terenu, czy nie.
Właściwość ta jest pozycją centrum Explosion . Jest definiowana w przestrzeni świata i nie jest wpływana przez rodzica Explosion.
Wartość pomiędzy 0 a 1, która kontroluje prędkość efektu cząstek.
Właściwość ta decyduje, czy efekt wizualny Explosion zostanie wyświetlony, czy nie.
Zdarzenia
Wypala się, gdy Explosion trafi w BasePart w jego Explosion.BlastRadius . Powraca część uderzona wraz z odległością części od Explosion.Position .
Właściwości
BlastPressure
Przykłady kodu
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
Przykłady kodu
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
Przykłady kodu
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)
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
Przykłady kodu
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
Position
Przykłady kodu
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
Visible
Przykłady kodu
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
Przykłady kodu
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)