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

This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.

Explosion Instantiation

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

Özet

Özellikler

Etkinlikler

Özellikler

BlastPressure

Paralel oku

BaseParts içine yapılan güç miktarını belirlemek için kullanılır Explosion.BlastRadius .

Şu anda uygulanan bu güç seviyesi, Explosion.Position 'den uzaklığa bağlı olarak değişmez.Sabit olmayan BaseParts çıkış noktasından eşit oranda uzaklaşacak, patlama yarıçapı içinde oldukları sürece mesafe verilirse.

Patlama basıncı, bir patlama nedeniyle parçaların hızlanmasını belirler.Katıların kırılma derecesini belirlemez.When Explosion.DestroyJointRadiusPercent 1 ile eşit olduğunda, Explosion.BlastRadius parçalar arasındaki tüm eklemler patlayacak, patlama basıncı 0'dan büyük olduğu sürece.

Patlama Basıncı da Terrain 'e verilen hasar miktarını belirlemez.Verilen patlama basıncı 0'dan büyüktür ve Explosion.ExplosionType patlamanın yarattığı kraterin boyutu yalnızca Explosion.BlastRadius tarafından belirlenir.

Patlama basıncını 0'a ayarlamak, patlamanın etkisini ortadan kaldırır ve geliştiriciler Explosion.Hit etkinliğini kullanarak kendi özel davranışlarını programlamak istediklerinde patlamalar için yararlıdır.

Kod Örnekleri

This sample contains a simple function that creates a custom explosion. The custom explosion will not break joints as Explosion.DestroyJointRadiusPercent is equal to 0. This means Humanoids will not be instantly killed as their neck joints are broken. In this example explosion.BlastPressure is equal to zero so as not to apply force or damage terrain but this can be changed.

The Explosion.Hit event is used to listen for contact. Once contact has been made the code will look for the parent model of the BasePart hit by the explosion. If that model exists, hasn't already been damaged and has a Humanoid in it damage will be applied based on distance from the explosion's origin.

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

Bu özellik, Explosion 'nin yarıçapını, milimetre olarak belirler. Bu özellik, 0 ile 100 arasındaki herhangi bir değeri kabul eder.

Bu yarıçap, patlamanın etki alanını belirler, patlama görüntülerinin boyutunu değil.Patlamanın görsel efektinin büyüklüğü, Patlama Yarıçapı'na rağmen aynıdır (Patlama Yarıçapı 0 olsa bile).

BaseParts patlama yarıçapı içindeki patlama etkilenecektir.Yani, eğer Explosion.BlastPressure 0'dan büyükse, güç parçalara uygulanacaktır.Patlama Yarıçapı içindeki eklerin kırılma derecesi Explosion.DestroyJointRadiusPercent 'ye bağlıdır.Explosion.Hit yarıçap içindeki herhangi bir şey için ateş edecek BasePart .

BaseParts yalnızca kısmen menzilde olsa bile Explosion.BlastRadius içinde dikkate alınır.

Kod Örnekleri

This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.

Explosion Instantiation

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

DestroyJointRadiusPercent

Paralel oku

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.

Örneğin, eğer Explosion.BlastRadius 100 olarak ayarlanır ve DestroyJointRadiusPercent 0.5 olarak ayarlanırsa, 50 damga içindeki herhangi bir eklem kırılacaktır.50 ve 100 çiviler arasındaki herhangi bir eklem yok edilmeyecekti, ancak Explosion gücü hala BaseParts uygulanacaktı.

Bu özellik, geliştiricilerin DestroyJointRadiusPercent'i 0'a ayarlayarak Explosions 'ölümcül olmayan' Humanoids yapmasına izin verir.Bu, karakterler Explosion ile temasa geçtiğinde boyun eklemi kırılmayacağı anlamına gelir.

Kod Örnekleri

This sample includes an example of how Explosions can be made non lethal to player characters.

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)

This sample contains a simple function that creates a custom explosion. The custom explosion will not break joints as Explosion.DestroyJointRadiusPercent is equal to 0. This means Humanoids will not be instantly killed as their neck joints are broken. In this example explosion.BlastPressure is equal to zero so as not to apply force or damage terrain but this can be changed.

The Explosion.Hit event is used to listen for contact. Once contact has been made the code will look for the parent model of the BasePart hit by the explosion. If that model exists, hasn't already been damaged and has a Humanoid in it damage will be applied based on distance from the explosion's origin.

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

Bu özellik, Explosion 'nin Terrain ile nasıl etkileşime gireceğini belirler. Bir Enum.ExplosionType değeridir ve üç seçeneğin birine ayarlanabilir.

  • Krater Yok - Patlamalar Araziye zarar vermeyecek
  • Kraterler - Patlamalar arazide kraterler oluşturacak
  • KraterlerVeÇöpler - Redndant, Kraterlerle aynı davranır

Patlama Türü, Terrain 'de kratere oluşturmak için ayarlanırsa, kratörün yarıçapı yaklaşık olarak Explosion.BlastRadius 'e eşit olacaktır.Kraterler, su dışındaki tüm Terrain malzemelerde oluşturulur.Kraterin büyüklüğü malzemeden etkilenmez, ancak bazı malzemeler diğerlerinden daha kaba kenarlar oluşturur.

Kod Örnekleri

This code sample includes an example of how the Explosion.ExplosionType property can be used to stop Explosions from damaging terrain. It is recommended to set the ExplosionType to NoCraters at the point of Explosion instantiation, but if that is not practical the code below will work.

Stop Explosions from Damaging Terrain

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

Bu özellik, Explosion 'nin merkezinin konumudur. Dünya uzayında tanımlanır ve Explosion ebeveyninin etkisi altında değildir.

patlamanın konumundaki çubukların içinde bulunuyorsa, patlama etkisi altında kalacaktır.

Bir patlamanın etkisi anlıktır.Bu, bir patlamanın konumunun ayarlanmasından sonra değiştirilebilmesine rağmen, iki farklı alanı etkileyemeyeceği anlamına gelir.Bir patlama bir kez 'patlamış' olduktan sonra, kısa bir süre sonra bir çocuğa mirasçısına aktardıktan sonra tekrar yapmayacaktır.Bazı durumlarda patlamanın görsel etkisi hareket edecek, ancak hiçbir etkisi olmayacak.

Bu nedenle geliştirici farklı bir konumda patlama görünmesini istiyorsa yeni bir patlama oluşturulmalıdır.

Kod Örnekleri

This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.

Explosion Instantiation

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

TimeScale

Paralel oku

Parçacık etkisinin hızını kontrol eden 0 ile 1 arasında bir değer.1'de normal hızda çalışır, 0.5'te yarı hızda çalışır ve 0'da zaman donar.

Visible

Paralel oku

Bu özellik, bir Explosion 'in görsel efektinin gösterilip gösterilmediğini belirler.

Görünür false olarak ayarlanırsa, patlama hala 'de etkili olacak, tek farkı görünmeyecek.

Bu özellik için bir kullanım, bir geliştiricinin kendi özel patlama etkilerini bir ParticleEmitter kullanarak yapması ve varsayılan Explosion işlevselliğini koruyarak olurdu.

Kod Örnekleri

This sample includes a function that will create an Explosion but replace the default Explosion visuals but those of a ParticleEmitter.

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

Etkinlikler

Hit

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 .

Bir Explosion 'nin etkisinin engeller tarafından bozulmadığını unutmayın, bu da diğer parçaların arkasında korunan parçalara hala vurulacağını ifade eder, çünkü korundukları BasePart arkaya sabitlenmiş olsa bile.

Bu etkinlik ayrıca Explosion.BlastPressure sıfıra eşit olduğunda da ateşlenecektir.Bu, geliştiricilerin patlamalar için kendi özel davranışlarını programlayabilmelerini sağlar, patlamanın etkisini BaseParts ve Terrain ortadan kaldırarak.

Bu olayın her BasePart vuruş için ateşleneceğini unutmayın.Bu, aynı oyuncu karakteri için birden fazla kez ateş edebileceği anlamına gelir (karakter Model birden fazla parçadan oluşur).Bu nedenle, Explosion.Hit etkinliğini kullanarak özel hasarı ele alırken karakterin zaten Explosion tarafından vurulduğunu görmek için bir kontrol uygulanması önerilir.

Parametreler

part: BasePart

The BasePart tarafından vurulan Explosion .

distance: number

Vuruşun Explosion.Position 'den uzaklığı.


Kod Örnekleri

This sample contains a simple function that creates a custom explosion. The custom explosion will not break joints as Explosion.DestroyJointRadiusPercent is equal to 0. This means Humanoids will not be instantly killed as their neck joints are broken. In this example explosion.BlastPressure is equal to zero so as not to apply force or damage terrain but this can be changed.

The Explosion.Hit event is used to listen for contact. Once contact has been made the code will look for the parent model of the BasePart hit by the explosion. If that model exists, hasn't already been damaged and has a Humanoid in it damage will be applied based on distance from the explosion's origin.

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)