Explosion

显示已弃用

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处

爆炸将力量应用到 BaseParts 内的爆炸 BlastRadius 内。 这些 force 会 击败

如果在体验运行时,Explosion的父级在数据模型中任何位置,它即将触发,并在几秒后变成未父级。它在此情况下不会被Instance:Destroy()摧毁,因此连接不会被切断。父级与所有实例都一样,在此情况下保留强有效引

注意,Explosion必须是Workspace的后代,才能播放爆炸视觉和物理/伤害效果。

爆炸效果

Humanoids 被爆炸杀死,因为爆炸会打破角色 Model 的颈部关接头。与 ForceField 模型交叉父母会保护所有其子从爆炸杀死效果。

如果您不希望要在 BaseParts 之间的关节被破坏,或者您想要实现自己的方式为 Humanoids 造成伤害,那么您建议将 Class.Explosion.DestroyJointRadiusPercent|DestroyJointRadiusPercent

爆炸还可以配置为对 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 内的零件都会被摧毁,提供 Class.Explosion.DestroyJointRadius 的爆炸压力大于

爆炸压力也不会确定提供的爆炸压力是否超过 0 。 提供的爆炸压力大于 0 且 Terrain 不是设置在 Enum.ExplosionType.NoCraters 创建的火山是由 Explosion.ExplosionType 决定。

将 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 内的 BlastRadius 将受到爆炸的影响。意味着,如果 Explosion.BlastPressure 大于 0,将适用力量到零件。 Class.Explos

BasePartsExplosion.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 英尺范围内的共同体都不会被销毁,但 Class.

此属性允许开发人员使 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 的交互方式。它是一个枚列值,可以设置为三个选项之一。

  • 无裂缝 - 爆炸不会对地形造成伤害
  • 火山口 - 爆炸会在地形上创建火山口
  • CraterAndDebris - 无重复,行为相同于Crater

如果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 爆炸位置的距离。

爆炸的效果是立即的。这意味着虽然位置的爆炸可以改变在它设置之后,但它不会影响两个不同的区域。一旦爆炸被“detonated”,很快就会在父辈对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)