Explosion

顯示已棄用項目

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡

在爆炸的 BaseParts 內,對 BlastRadius 加以力量。這種力量會在爆炸的 Class

如果體驗正在執行時,任何 Explosion 是在資料模型中的任何位置,它會立即崩溃,並且在幾秒鐘內變成未屬性。它不會在 Instance:Destroy() 中被摧毀,因此連接不會被�

注意,Explosion 必須是 Workspace 的後代,才能播放爆炸視覺和物理/傷害效果才會有影響。

爆炸效果

Humanoids 被爆炸擊殺,因為爆炸會斷裂角色的 Model 臥頸關組合。與 ForceField 模型親綁會保護所有其子從爆炸擊殺效果。

如果您不想要在 BaseParts 之間的關節被斷斷,或者您想要實現自己的方式來傷害 Humanoids ,建議您將 Class.Explosion.DestroyJointRadiusPercent|Destroy

爆炸也可以設定為對 Terrain 造成傷害,創建孔,按照 ExplosionType 屬性設定。

注意,爆炸的效果會因 受阻礙而發生延遲,因此在其他零件/地形後方的零件/地形仍會受影響。

範例程式碼

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

概要

屬性

活動

屬性

BlastPressure

平行讀取

用於確定 BaseParts 被捕捉在 Explosion.BlastRadius 中的力量。

目前此力應用程式的力量不會因為Explosion.Position距離而變化。無夾定的BaseParts會在爆破範圍內無論距離如何提升。

爆炸壓力會決定零件因爆炸而產生的加速度。它不會決定零件是否被破壞。當 Explosion.DestroyJointRadiusPercent 等於 1 時,所有零件之間的關節都會被摧毀,提供 Explosion.BlastRadius 的爆炸壓力大於 0 時,所有零件都會被

爆壓也不會決定給 Terrain 的傷害。提供的爆壓大於 0 和 Explosion.ExplosionType 未設為 Enum.ExplosionType.NoCraters 創建的火山是由爆壓 Explosion.BlastRadius 決定

將 BlastPressure 設為 0 會抹滅爆炸的效果,並且對開發人員重要,當他們想要使用 Explosion.Hit 事件程式自訂爆炸行為。

範例程式碼

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

平行讀取

此屬性決定 Explosion 的範圍,以 stud 計。此屬性接受任何值之間 0 和 100。

此範圍將爆炸的效果區域定義為爆炸視覺的大小,而不是 BlastRadius (即使是 0) 。爆炸的視覺效果大小無論如何都一樣。

BaseParts 內的爆炸將受到爆炸的影響。意味著,如果 Explosion.BlastPressure 大於 0,力量將被應用到零件。爆炸範

BaseParts 被視為在 Explosion.BlastRadius 內,即使只是部分範圍內。

範例程式碼

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

平行讀取

用於將 Explosion.BlastRadius 的比例設置在 0 和 1 之間,在此範圍內所有關節都將被摧毀。任何超出此範圍的內容將只有 Explosion 的力量適用。

例如,如果 Explosion.BlastRadius 設為 100 ,而 DestroyJointRadiusPercent 設為 0.5,任何超過範圍 50 的關節都會損壞。任何超過範圍 50 和 100 的關節都不會被摧毀

這個屬性允許開發人員將 Explosions 變成 Humanoids ,以設定 DestroyJointRadiusPercent 為 0。這意味著頸部關節不會被斷裂,當角色與 Explosion 接觸時。

範例程式碼

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

平行讀取

這個屬性決定 ExplosionTerrain 的交互方式。它是一個枚列值 Class.ExplosionType ,可以設置為三個選項之一。

  • 無法攻擊者 - 爆炸不會傷害地形
  • 火山口 - 爆炸會在地形中創造火山口
  • CratersAndDebris - 重複,與Craters相同

如果 ExplosionType 設定在 Terrain 中創建火山口,火山口的範圍將大約等同於 Explosion.BlastRadius 。火山口是在所有 Terrain 材料中,除水以外,其大小不會受到材料的影響。火山口的大小不會受

範例程式碼

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

隱藏
未複製
平行讀取

Position

平行讀取

此屬性是 Explosion 的中心位置。它在世界空間中定義,並且不受 Explosion 的父元素親影響。

BaseParts 會受到 Explosion 的影響,如果它們位於 Explosion.BlastRadius 的爆炸範圍內。

爆炸的效果是即時的。這意味著爆炸的位置在設定後即可變更,但在它被設定後兩個區域之間無法影響。一旦爆炸被「爆炸」,在父輩對一個子孫的 Class.Workspace 後,它就不會再次發生。在某些情況下,爆炸的視覺效果會移動,但它沒有效果。

因此,如果開發人員想要爆炸出現在不同的位置,就必須建立新的爆炸。

範例程式碼

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

平行讀取

一個值在 0 和 1 之間,控制粒子效果的速度。在 1 時,它以正常速度執行,在 0.5 時,它以半速度執行,並在 0 時凍結時間。

Visible

平行讀取

此屬性決定是否顯示或不顯示 Explosion 的視覺效果。

當 Visible 設為 false 時,爆炸仍會影響 BaseParts 在其 Explosion.BlastRadius 中,唯一的區別是它不會被看到。

這個屬性的使用方式之一是,開發人員可以使用 ParticleEmitter 來自己製作自訂爆炸效果,而且保留 Explosion 的預設功能。

範例程式碼

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

方法

活動

Hit

發生在 Explosion 擊中 BasePart 內的 Explosion.BlastRadius 內。返回零件擊以及零件從 1>Class.Explosion.Position1> 的距離。

注意,Explosion 的效果對障礙物不會受到影響,這意味著在其後的零件仍然會被擊中,即使BasePart 在障礙物後面錨定。

此事件還會在 Explosion.BlastPressure 與零相等時發生。這表示開發人員可以程式自己的自訂行為以對爆炸造成影響,而不會受到爆炸對 BasePartsTerrain 的影響。

注意,這個事件會在每次擊中 BasePart 時發生。這意味著它可以發生多次對同一個玩家角色 (由角色 Model 組成的多個部分)。因此,當使用 Explosion.Hit 事件來

參數

part: BasePart

Class.BasePart 被 Explosion 擊中。

distance: number

Explosion.Position 的距離。


範例程式碼

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)