Explosion
*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.
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
BaseParts içine yapılan güç miktarını belirlemek için kullanılır Explosion.BlastRadius .
Bu özellik, Explosion 'nin yarıçapını, mil olarak belirler.Bu yarıçap, patlamanın etki alanını belirler, patlama görüntülerinin boyutunu değil.
Tüm eklemlerin yok edileceği aralıkta, 0 ile 1 arasındaki Explosion.BlastRadius oranı ayarlamak için kullanılır, içinde tüm eklemler yok edilecek.Bu aralığın dışındaki her şey sadece ona Explosion gücü uygulanacaktır.
Bu özellik, Explosion 'nin Terrain ile nasıl etkileşime gireceğini belirler. Patlamaların arazide hasara neden olup olmayacağını ayarlamak için kullanılır.
Bu özellik, Explosion 'nin merkezinin konumudur. Dünya uzayında tanımlanır ve Explosion ebeveyninin etkisi altında değildir.
Parçacık etkisinin hızını kontrol eden 0 ile 1 arasındaki değer.
Bu özellik, bir Explosion 'in görsel efektinin gösterilip gösterilmediğini belirler.
Olaylar
Fires when the Explosion bir parçanın BasePart içinde bir Explosion.BlastRadius vurduğunda ateş eder. Parçanın bölümüne çarpan mesafeyi ile birlikte parçaya vurur Explosion.Position .
Özellikler
BlastPressure
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
Kod Örnekleri
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
Visible
Kod Örnekleri
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
Kod Örnekleri
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)