폭발은 폭발의 BaseParts 내에서 힘을 적용합니다.An explosion applies force to within the explosion's BlastRadius .이 힘은 부품 사이의 JointInstances 와 WeldConstraints 을 파괴하고 Humanoid 에 의해 보호되지 않는 문자를 죽입니다 ForceField .Constraints 폭발로 인해 부서지지 않습니다.
경험이 실행되는 동안 데이터 모델의 어딘가에서 Explosion가 부모로 지정되면 즉시 시작되고, 몇 초 내에 부모로부터 분리됩니다.이 경우 Instance:Destroy()로 파괴되지 않으므로 연결이 끊어지지 않고 부모가 잠겨지지 않습니다.모든 인스턴스와 마찬가지로, 강력한 참조를 유지하면 Explosion 가비지 수집되지 않습니다.
폭발 시각이 재생되고 물리적/손상 효과가 영향을 미치려면 Explosion 가 하위 요소여야 하는 점에 유의하십시오. Note that an must be a descendant of Workspace for the explosion visuals to play and the physical/damaging effects to have an impact.
폭발 효과
Humanoids 는 폭발로 인해 캐릭터 Model 목 관절이 파괴되면서 폭발로 죽습니다.모델에 부모 ForceField 를 지정하면 모든 자식이 폭발 처치 효과로부터 보호됩니다.
BaseParts에서 조인이 깨지지 않도록 하거나 Humanoids에 대한 자신의 수식을 구현하려는 경우, 폭발의 결과를 처리하기 위해 DestroyJointRadiusPercent를 0으로 설정하고 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)