Explosion

Artık kullanılmayanları göster

*Bu içerik, yapay zekâ (beta) kullanılarak çevrildi ve hatalar içerebilir. Sayfayı İngilizce görüntülemek için buraya tıkla.

Bir patlama, patlamanın BaseParts içindeki güce uygular BlastRadius .Bu kuvvet parçalar arasında JointInstances ve WeldConstraints kırar ve bir Humanoid tarafından korunmayan karakterler öldürür ForceField .Constraints bir patlama tarafından kırılmayacak.

Deneyim çalışırken herhangi bir yerdeki bir Explosion ebeveynlik yapılırsa, hemen kalkar ve birkaç saniye içinde ebeveynsiz hale gelir.Bu durumda Instance:Destroy() ile yok edilmediğinden bağlantılar kopmaz ve ebeveyn kilitlenmez.Tüm durumlarda olduğu gibi, güçlü bir referansı Explosion korumak, onun çöp toplanmasını engelleyecektir.

Patlama görüntülerinin oynatılması ve fiziksel/zarar verici etkilerin bir etkiye sahip olması için bir Explosion 'in bir Workspace 'in bir altı olması gerektiğini unutmayın.

Patlama Etkileri

Humanoids patlamalar tarafından öldürülür, çünkü patlama karakter Model boyun eklemini kırar.Bir modelde ebeveynlik yapmak, tüm çocukları patlama öldürme etkisinden koruyacaktır. ForceField

BaseParts arasındaki eklemlerin kırılmasını istemiyorsanız veya Humanoids 'e hasar vermek için kendi formülünüzü uygulamak istiyorsanız, patlamanın sonucunu ele almak için DestroyJointRadiusPercent 'i 0'a ayarlamanız ve patlamanın sonucunu ele almak için Hit etkinliğini kullanmanız önerilir.

Patlamalar ayrıca Terrain hasara vermek için yapılandırılabilir, kraterler oluşturmak, ExplosionType özelliği aracılığıyla yapılandırılmış olarak.

Bir patlamanın etkisinin engeller tarafından bozulmadığını unutmayın; yani, diğer parçalar/alanların arkasında korunan parçalar/alanlar hala etkilenecek.

Kod Örnekleri

Bu kod örneği, 0, 10, 0'da oyunda büyük bir patlama oluşturan kısa bir parça içerir.

Patlama Anında Oluşturma

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

Özet

Özellikler

Olaylar

Özellikler

BlastPressure

Paralel oku

Kod Örnekleri

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

Paralel oku

Kod Örnekleri

Patlama Anında Oluşturma

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

DestroyJointRadiusPercent

Paralel oku

Kod Örnekleri

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

Paralel oku

Kod Örnekleri

Araziyi hasara uğratan patlamaları durdur

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

Gizli
Çoğaltılmamış
Paralel oku

Position

Paralel oku

Kod Örnekleri

Patlama Anında Oluşturma

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

TimeScale

Paralel oku

Visible

Paralel oku

Kod Örnekleri

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))

Yöntemler

Olaylar

Hit

Parametreler

part: BasePart
distance: number

Kod Örnekleri

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)