Explosion
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
爆発は、爆発内の BaseParts に力を適用します。BlastRadius 。この力は、パーツの間の JointInstances と WeldConstraints を破壊し、Humanoid に保護されていないキャラクターを殺します。これは、ForceField によって保護されていないパーツの間で起こります。Constraints は爆発によって壊れません。
エクスペリエンスが実行されている間、データモデルのどこかで Explosion が親になっている場合、すぐに起動し、数秒以内に親から切り離されます。この場合、Instance:Destroy() で破壊されないので、接続が切断されず、親がロックされない。すべてのインスタンスと同様、強い参照を Explosion 保持すると、ゴミ回収されるのを防げます。
爆発ビジュアルが再生され、物理/破壊効果が影響を与えるためには、Explosion がWorkspaceの子孫である必要があることに注意してください。
爆発効果
Humanoids は爆発で殺され、爆発がキャラクターの Model 首関節を破壊するときに殺されます。親がモデルに ForceField をパーティングすると、すべての子供が爆発キル効果から保護されます。
BaseParts からHumanoidsへの接合が壊れないようにしたい、またはDestroyJointRadiusPercentへのダメージフォーミュラを実装したい場合、爆発の結果を処理するためにHitイベントを使用することをお勧めします。
爆発は、Terrain にダメージを与えるように構成することもでき、ExplosionType プロパティを通じて設定されるように、クレーターを作成します。
爆発の効果は、 障害物によって中断されない 、つまり、他のパーツ/地形の後ろにシールドされたパーツ/地形がまだ影響を受けることに注意してください。
コードサンプル
このコードサンプルには、0、10、0 でゲーム内で大爆発を生成する短いスニペットが含まれています。
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- 地形を損傷する
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace
概要
プロパティ
BaseParts に捕まえられた力の量を決定するために使用されます。Explosion.BlastRadius に捕まえられた力の量を決定するために使用されます。
このプロパティは、スタッドで Explosion の半径を決定します。この半径は爆発の視覚サイズではなく、爆発の効果エリアを決定します。
0から1の間の Explosion.BlastRadius の割合を設定し、すべてのジョイントが破壊される領域を設定するために使用されます。この範囲外のものは、Explosion フォースが適用されるだけです。
このプロパティは、Explosion が Terrain とどのように相互作用するかを決定します。爆発が地形にダメージを与えるかどうかを設定するのに使用されます。
このプロパティは、Explosion の中心の位置です。ワールドスペースで定義され、Explosion 親の影響を受けません。
パーティクル効果の速度を制御する 0 から 1 の値。
このプロパティは、Explosion の視覚効果が表示されるかどうかを決定します。
イベント
ファイアが が自分の 内に をヒットすると発動します。部品からの距離と部品をヒットした部分を返します。
プロパティ
BlastPressure
コードサンプル
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
コードサンプル
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- 地形を損傷する
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace
DestroyJointRadiusPercent
コードサンプル
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
コードサンプル
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
コードサンプル
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- 地形を損傷する
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspace
TimeScale
Visible
コードサンプル
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
パラメータ
コードサンプル
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)