Explosion
*Konten ini diterjemahkan menggunakan AI (Beta) dan mungkin mengandung kesalahan. Untuk melihat halaman ini dalam bahasa Inggris, klik di sini.
Sebuah ledakan menerapkan kekuatan ke BaseParts dalam ledakan BlastRadius .Kekuatan ini mematahkan JointInstances dan WeldConstraints antara bagian dan membunuh Humanoid karakter yang tidak dilindungi oleh ForceField .Constraints tidak akan rusak oleh ledakan.
Jika Explosion adalah orang tua di mana saja di model data saat pengalaman berjalan, itu segera diaktifkan dan, dalam beberapa detik, menjadi tidak berada di bawah.Tidak dihancurkan dengan Instance:Destroy() dalam kasus ini, sehingga koneksi tidak terputus dan orangtua tidak dikunci.Seperti halnya semua instansi, menyimpan referensi kuat sebuah Explosion akan mencegahnya dikumpulkan sampah.
Perhatikan bahwa sebuah Explosion harus menjadi keturunan dari Workspace untuk visual ledakan untuk dimainkan dan efek fisik/merusak untuk memiliki dampak.
Efek Ledakan
Humanoids dibunuh oleh ledakan, karena ledakan mematahkan persatuan leher karakter Model .Membesarkan anak ForceField ke model akan melindungi semua anaknya dari efek bunuh ledakan.
Jika Anda tidak ingin persambungan antara BaseParts untuk dipatahkan, atau Anda ingin menerapkan formula Anda sendiri untuk merusak Humanoids , disarankan agar Anda mengatur DestroyJointRadiusPercent menjadi 0 dan menggunakan peristiwa Hit untuk menangani hasil ledakan.
Ledakan juga dapat dikonfigurasi untuk merusak Terrain , menciptakan krater, seperti yang dikonfigurasi melalui properti ExplosionType.
Perhatikan bahwa efek ledakan tidak tidak terganggu oleh hambatan, artinya bagian/tanah yang diselubungi di belakang bagian/tanah lainnya masih akan terpengaruh.
Contoh Kode
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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
Rangkuman
Properti
Digunakan untuk menentukan jumlah kekuatan yang diterapkan ke BaseParts ditangkap di Explosion.BlastRadius .
Properti ini menentukan radius dari Explosion , dalam stud.Radius ini menentukan area efek ledakan, bukan ukuran visual ledakan.
Digunakan untuk mengatur proporsi dari Explosion.BlastRadius, antara 0 dan 1, di mana semua sambungan akan hancur.Apa pun di luar rentang ini hanya akan memiliki kekuatan Explosion yang diterapkan kepadanya.
Properti ini menentukan bagaimana Explosion akan berinteraksi dengan Terrain . Digunakan untuk menetapkan apakah ledakan akan menyebabkan kerusakan pada medan atau tidak.
Properti ini adalah posisi pusat dari Explosion . Ini didefinisikan di ruang dunia dan tidak dipengaruhi oleh orang tua Explosion.
Nilai antara 0 dan 1 yang mengontrol kecepatan efek partikel.
Properti ini menentukan apakah efek visual dari Explosion ditampilkan atau tidak.
Acara
Memicu ketika Explosion menyerang BasePart di dalam Explosion.BlastRadius . Mengembalikan bagian yang dipukul bersama dengan jarak bagian dari Explosion.Position .
Properti
BlastPressure
Digunakan untuk menentukan jumlah kekuatan yang diterapkan ke BaseParts ditangkap di Explosion.BlastRadius .
Saat ini tingkat kekuatan yang diterapkan tidak bervariasi berdasarkan jarak dari Explosion.Position .Unanchored BaseParts tidak akan mempercepat sama jauh dari asal tergantung pada jarak yang diberikan selama mereka berada dalam radius ledakan.
Tekanan ledakan menentukan akselerasi bagian karena ledakan.Ini tidak menentukan tingkat di mana persambungan rusak.Ketika Explosion.DestroyJointRadiusPercent sama dengan 1 semua sambungan antara bagian di Explosion.BlastRadius akan hancur asalkan Tekanan Ledakan lebih besar dari 0.
Tekanan ledakan juga tidak menentukan jumlah kerusakan yang diberikan ke Terrain .Tekanan ledakan yang disediakan lebih besar dari 0 dan Explosion.ExplosionType tidak ditetapkan ke Enum.ExplosionType.NoCraters ukuran crater yang dibuat ditentukan secara eksklusif oleh Explosion.BlastRadius .
Mengatur Tekanan Ledakan ke 0 menghilangkan efek ledakan dan berguna ketika pengembang ingin memprogram perilaku khusus mereka sendiri untuk ledakan menggunakan peristiwa Explosion.Hit.
Contoh Kode
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.
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
Properti ini menentukan radius dari Explosion , dalam stud. Properti ini menerima nilai apa pun antara 0 dan 100.
Radius ini menentukan area efek ledakan, bukan ukuran visual ledakan.Ukuran efek visual ledakan sama terlepas dari BlastRadius (bahkan jika BlastRadius adalah 0).
BaseParts di dalam BlastRadius akan terpengaruh oleh ledakan.Artinya, jika Explosion.BlastPressure lebih besar dari 0, kekuatan akan diterapkan ke bagian.Degree di mana persambungan rusak dalam BlastRadius tergantung pada Explosion.DestroyJointRadiusPercent . Explosion.Hit akan menembak untuk setiap setiap BasePart dalam radius.
BaseParts dianggap dalam Explosion.BlastRadius bahkan jika mereka hanya sebagian berada dalam jangkauan.
Contoh Kode
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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
Digunakan untuk mengatur proporsi dari Explosion.BlastRadius, antara 0 dan 1, di mana semua sambungan akan hancur.Apa pun di luar rentang ini hanya akan memiliki kekuatan Explosion yang diterapkan kepadanya.
Sebagai contoh, jika Explosion.BlastRadius ditetapkan ke 100 dan DestroyJointRadiusPercent ditetapkan ke 0,5, setiap joint dalam radius 50 stud akan rusak.Setiap persambungan antara rentang 50 dan 100 stud tidak akan hancur, tetapi kekuatan Explosion masih akan diterapkan ke BaseParts.
Properti ini memungkinkan pengembang untuk membuat Explosions 'tidak mematikan' ke Humanoids dengan menetapkan DestroyJointRadiusPercent ke 0.Ini berarti sendi leher tidak akan rusak ketika karakter berhubungan dengan Explosion.
Contoh Kode
This sample includes an example of how Explosions can be made non lethal to player characters.
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.
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
Properti ini menentukan bagaimana Explosion akan berinteraksi dengan Terrain . Ini adalah nilai Enum.ExplosionType dan dapat ditetapkan ke salah satu dari tiga opsi.
- Tidak ada NoCraters - Ledakan tidak akan merusak Tanah
- Krater - Ledakan akan membuat krater di Tanah
- Krater dan Debris - Redundan, berperilaku sama dengan Krater
Jika ExplosionType ditetapkan untuk membuat crater di Terrain , radius crater akan kira-kira sama dengan Explosion.BlastRadius .Krater dibuat di semua Terrain materi lain selain air.Ukuran crater tidak dipengaruhi oleh material, meskipun beberapa material membuat sudut yang lebih kasar daripada yang lain.
Contoh Kode
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.
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
Properti ini adalah posisi pusat dari Explosion . Ini didefinisikan di ruang dunia dan tidak dipengaruhi oleh orang tua Explosion.
BaseParts akan dipengaruhi oleh Explosion jika mereka berada dalam Explosion.BlastRadius stud posisi ledakan.
Efek dari ledakan adalah instan.Ini berarti bahwa meskipun posisi ledakan dapat diubah setelah ditetapkan tidak dapat mempengaruhi dua area yang berbeda.Setelah ledakan 'detonasi', tidak lama setelah membesarkannya ke keturunan dari Workspace, ia tidak akan melakukannya lagi.Dalam beberapa kasus, efek visual ledakan akan bergerak tetapi tidak akan berpengaruh.
Untuk alasan ini, ledakan baru harus dibuat jika pengembang ingin ledakan muncul di posisi yang berbeda.
Contoh Kode
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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
Nilai antara 0 dan 1 yang mengontrol kecepatan efek partikel.Pada 1 berjalan dengan kecepatan normal, pada 0.5 berjalan setengah kecepatan, dan pada 0 membekukan waktu.
Visible
Properti ini menentukan apakah efek visual dari Explosion ditampilkan atau tidak.
Ketika Visible diatur ke false, ledakan masih akan mempengaruhi BaseParts di dalamnya Explosion.BlastRadius, perbedaannya hanya tidak akan terlihat.
Satu penggunaan untuk properti ini akan menjadi untuk seorang pengembang untuk membuat efek ledakan khusus mereka sendiri menggunakan ParticleEmitter , sambil menyimpan fungsi default Explosion .
Contoh Kode
This sample includes a function that will create an Explosion but replace the default Explosion visuals but those of a ParticleEmitter.
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))
Metode
Acara
Hit
Memicu ketika Explosion menyerang BasePart di dalam Explosion.BlastRadius . Mengembalikan bagian yang dipukul bersama dengan jarak bagian dari Explosion.Position .
Perhatikan bahwa efek dari Explosion tidak terganggu oleh hambatan, ini berarti bagian yang dilindungi di belakang bagian lain masih akan terkena, bahkan jika BasePart yang dilindungi di belakang diancore.
Peristiwa ini juga akan terjadi ketika Explosion.BlastPressure sama dengan nol.Ini berarti pengembang dapat memprogram perilaku khusus mereka sendiri untuk ledakan dengan menghilangkan pengaruh ledakan pada BaseParts dan Terrain.
Perhatikan bahwa acara ini akan menembak untuk setiap BasePart pukul.Ini berarti dapat menembak beberapa kali untuk karakter pemain yang sama (karena karakter Model terdiri dari beberapa bagian).Untuk alasan ini ketika menangani kerusakan khusus menggunakan peristiwa Explosion.Hit , disarankan untuk menerapkan pemeriksaan untuk melihat apakah karakter sudah terkena oleh Explosion .
Parameter
Jarak hit dari Explosion.Position .
Contoh Kode
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.
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)