코드 샘플
폭발 인스턴스화
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- 지형에 피해를 줍니다.
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspaceAPI 참조
속성
BlastPressure
코드 샘플
사용자 정의 폭발
local function customExplosion(position, radius, maxDamage)
local explosion = Instance.new("Explosion")
explosion.BlastPressure = 0 -- 이는 여전히 부품에 속도를 적용하기 위해 더 높게 설정될 수 있습니다
explosion.DestroyJointRadiusPercent = 0 -- 관절은 안전합니다
explosion.BlastRadius = radius
explosion.Position = position
-- 명중된 모델을 추적할 테이블을 설정합니다
local modelsHit = {}
-- 접촉을 듣습니다
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- 이 모델이 이미 명중되었는지 확인합니다
if modelsHit[parentModel] then
return
end
-- 이 모델을 명중된 것으로 기록합니다
modelsHit[parentModel] = true
-- humanoid를 찾습니다
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- 거리를 0과 1 사이의 값으로 가져옵니다
distanceFactor = 1 - distanceFactor -- 낮을수록 가까움 == 더 많은 피해가 되도록 반전합니다
humanoid:TakeDamage(maxDamage * distanceFactor) -- ForceFields를 존중하기 위한 TakeDamage
end
end
end)
explosion.Parent = game.Workspace
-- Roblox는 몇 초 후에 폭발을 제거하지만 파괴하지는 않습니다.
-- .Hit 연결이 끊어지도록 폭발이 제거되면 이를 파괴합니다.
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 = workspaceDestroyJointRadiusPercent
코드 샘플
비치사 폭발
local function onDescendantAdded(instance)
if instance:IsA("Explosion") then
local explosion = instance
explosion.DestroyJointRadiusPercent = 0
local destroyJointRadiusPercent = 1
explosion.Hit:Connect(function(part, distance)
-- 부품이 관절을 부술 수 있는 범위인지 확인
if distance <= destroyJointRadiusPercent * explosion.BlastRadius then
-- 부품이 캐릭터에 속하지 않는지 확인
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 -- 이는 여전히 부품에 속도를 적용하기 위해 더 높게 설정될 수 있습니다
explosion.DestroyJointRadiusPercent = 0 -- 관절은 안전합니다
explosion.BlastRadius = radius
explosion.Position = position
-- 명중된 모델을 추적할 테이블을 설정합니다
local modelsHit = {}
-- 접촉을 듣습니다
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- 이 모델이 이미 명중되었는지 확인합니다
if modelsHit[parentModel] then
return
end
-- 이 모델을 명중된 것으로 기록합니다
modelsHit[parentModel] = true
-- humanoid를 찾습니다
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- 거리를 0과 1 사이의 값으로 가져옵니다
distanceFactor = 1 - distanceFactor -- 낮을수록 가까움 == 더 많은 피해가 되도록 반전합니다
humanoid:TakeDamage(maxDamage * distanceFactor) -- ForceFields를 존중하기 위한 TakeDamage
end
end
end)
explosion.Parent = game.Workspace
-- Roblox는 몇 초 후에 폭발을 제거하지만 파괴하지는 않습니다.
-- .Hit 연결이 끊어지도록 폭발이 제거되면 이를 파괴합니다.
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)Position
코드 샘플
폭발 인스턴스화
local explosion = Instance.new("Explosion")
explosion.BlastRadius = 60
explosion.ExplosionType = Enum.ExplosionType.Craters -- 지형에 피해를 줍니다.
explosion.Position = Vector3.new(0, 10, 0)
explosion.Parent = workspaceVisible
코드 샘플
폭발 커스텀 비주얼
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 -- 이는 여전히 부품에 속도를 적용하기 위해 더 높게 설정될 수 있습니다
explosion.DestroyJointRadiusPercent = 0 -- 관절은 안전합니다
explosion.BlastRadius = radius
explosion.Position = position
-- 명중된 모델을 추적할 테이블을 설정합니다
local modelsHit = {}
-- 접촉을 듣습니다
explosion.Hit:Connect(function(part, distance)
local parentModel = part.Parent
if parentModel then
-- 이 모델이 이미 명중되었는지 확인합니다
if modelsHit[parentModel] then
return
end
-- 이 모델을 명중된 것으로 기록합니다
modelsHit[parentModel] = true
-- humanoid를 찾습니다
local humanoid = parentModel:FindFirstChild("Humanoid")
if humanoid then
local distanceFactor = distance / explosion.BlastRadius -- 거리를 0과 1 사이의 값으로 가져옵니다
distanceFactor = 1 - distanceFactor -- 낮을수록 가까움 == 더 많은 피해가 되도록 반전합니다
humanoid:TakeDamage(maxDamage * distanceFactor) -- ForceFields를 존중하기 위한 TakeDamage
end
end
end)
explosion.Parent = game.Workspace
-- Roblox는 몇 초 후에 폭발을 제거하지만 파괴하지는 않습니다.
-- .Hit 연결이 끊어지도록 폭발이 제거되면 이를 파괴합니다.
explosion.AncestryChanged:Connect(function()
if not explosion.Parent then
explosion:Destroy()
end
end)
end
customExplosion(Vector3.new(0, 10, 0), 12, 50)