Explosion

แสดงที่เลิกใช้งานแล้ว

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่

การระเบิดใช้แรงกับ BaseParts ภายในการระเบิด BlastRadiusแรงนี้ทำลาย JointInstances และ WeldConstraints ระหว่างชิ้นส่วนและฆ่า Humanoid ตัวอักษรที่ไม่ได้รับการป้องกันโดย Class.ForceField``Class.Constraint|Constraints จะไม่ถูกทำลายโดยการระเบิด

หาก Explosion ได้รับการสืบทอดที่ใดก็ได้ในโมเดลข้อมูลในขณะที่ประสบการณ์กําลังดําเนินอยู่ มันจะถูกปิดทันทีและภายในไม่กี่วินาทีก็จะกลายเป็นไม่มีพ่อแม่ไม่ถูกทําลายด้วย Instance:Destroy() ในกรณีนี้ดังนั้นการเชื่อมต่อจะไม่ถูกตัดการเชื่อมต่อและพ่อจะไม่ถูกล็อคเช่นเดียวกับกรณีทั้งหมด การเก็บอ้างอิงที่แข็งแกร่งไว้ที่ Explosion จะป้องกันไม่ให้มันถูกเก็บขยะ

โปรดทราบว่า Explosion จะต้องเป็นลูกหลานของ Workspace เพื่อให้ภาพการระเบิดเล่นและผลกระทบทางกายภาพ/ทางอันตรายเกิดขึ้น

เอฟเฟกต์การระเบิด

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 , ในสตัด รัศมีนี้กำหนดพื้นที่ผลกระทบของการระเบิดไม่ใช่ขนาดของภาพกราฟิกของการระเบิด

  • อ่านพร้อมๆ กัน

    ใช้เพื่อตั้งค่าสัดส่วนของ Explosion.BlastRadius ระหว่าง 0 และ 1 ซึ่งจะทำลายข้อต่อทั้งหมดสิ่งใดอยู่นอกเหนือจากช่วงนี้จะมีแรง Explosion ที่ใช้กับมันเท่านั้น

  • อ่านพร้อมๆ กัน

    คุณสมบัตินี้กำหนดวิธีที่ Explosion จะโต้ตอบกับ Terrain ใช้เพื่อตั้งค่าว่าการระเบิดจะสร้างความเสียหายให้กับพื้นที่หรือไม่

  • ซ่อนอยู่
    ไม่ซ้ำ
    อ่านพร้อมๆ กัน
  • อ่านพร้อมๆ กัน

    คุณสมบัตินี้เป็นตำแหน่งศูนย์กลางของ Explosion มันถูกกำหนดในพื้นที่โลกและไม่ได้รับอิทธิพลจาก Explosion ผู้ปกครอง

  • อ่านพร้อมๆ กัน

    มูลค่าระหว่าง 0 และ 1 ที่ควบคุมความเร็วของเอฟเฟกต์อนุภาค

  • อ่านพร้อมๆ กัน

    คุณสมบัตินี้กำหนดว่าจะแสดงเอฟเฟกต์ภาพของ Explosion หรือไม่

อีเวนต์

คุณสมบัติ

BlastPressure

อ่านพร้อมๆ กัน

ใช้เพื่อกำหนดปริมาณแรงที่ใช้กับ BaseParts ที่จับได้ใน Explosion.BlastRadius

ขณะนี้ระดับแรงที่ใช้ไม่แตกต่างกันขึ้นอยู่กับระยะทางจาก Explosion.Positionไม่ได้รับการยึดถือ BaseParts จะเร่งความเร็วเท่าเทียบกับจุดเริ่มต้นโดยไม่คำนึงถึงระยะทางที่พวกเขาอยู่ภายในรัศมีการระเบิด

ความดันการระเบิดกำหนดอัตราเร่งของชิ้นส่วนเนื่องจากการระเบิดมันไม่ได้กำหนดระดับที่ข้อต่อถูกทำลายเมื่อ Explosion.DestroyJointRadiusPercent เท่ากับ 1 ทุกข้อต่อระหว่างชิ้นส่วนใน Explosion.BlastRadius จะถูกทําลายหากความดันระเบิดมากกว่า 0

ความดันระเบิดยังไม่ตัดสินจำนวนความเสียหายที่ให้กับ Terrainความดันระเบิดที่จัดให้มากกว่า 0 และ Explosion.ExplosionType ไม่ได้ตั้งค่าเป็น Enum.ExplosionType.NoCraters ขนาดของหลุมที่สร้างถูกกำหนดโดย Explosion.BlastRadius โดยเฉพาะอย่างยิ่ง

การตั้งค่าแรงดันระเบิดเป็น 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 ในสตัด คุณสมบัตินี้รองรับค่าใดๆ ระหว่าง 0 และ 100

รัศมีนี้กำหนดพื้นที่ของผลกระทบของการระเบิดไม่ใช่ขนาดของภาพกราฟิกของการระเบิดขนาดของเอฟเฟกต์ภาพการระเบิดเป็นเช่นเดียวกันไม่ว่า BlastRadius (แม้ว่า BlastRadius จะเป็น 0)

BaseParts ภายในรัศมีการระเบิดจะได้รับผลกระทบจากการระเบิดความหมายคือถ้า Explosion.BlastPressure มากกว่า 0 แรงจะถูกใช้กับชิ้นส่วนองศาที่ข้อต่อถูกทำลายภายในรัศมีระเบิดขึ้นอยู่กับ Explosion.DestroyJointRadiusPercent .Explosion.Hit จะยิงสำหรับทุกครั้งที่ BasePart ภายในรัศมี

BaseParts ถูกพิจารณาภายใน Explosion.BlastRadius แม้ว่าพวกเขาจะอยู่ในระยะเพียงบางส่วน

ตัวอย่างโค้ด

ตัวอย่างโค้ดนี้รวมถึงบรรทัดสั้นที่สร้างการระเบิดขนาดใหญ่ในเกมที่ 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

DestroyJointRadiusPercent

อ่านพร้อมๆ กัน

ใช้เพื่อตั้งค่าสัดส่วนของ Explosion.BlastRadius ระหว่าง 0 และ 1 ซึ่งจะทำลายข้อต่อทั้งหมดสิ่งใดอยู่นอกเหนือจากช่วงนี้จะมีแรง Explosion ที่ใช้กับมันเท่านั้น

ตัวอย่างเช่น หาก Explosion.BlastRadius ถูกตั้งค่าเป็น 100 และ DestroyJointRadiusPercent ถูกตั้งค่าเป็น 0.5 จุดที่อยู่ในรัศมีของ 50 สตัดจะถูกทำลายข้อต่อใดๆ ระหว่างช่วงของ 50 และ 100 สตัดจะไม่ถูกทําลาย แต่แรง Explosion จะยังคงถูกใช้กับ BaseParts

คุณสมบัตินี้ช่วยให้นักพัฒนาสามารถทำให้ 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

อ่านพร้อมๆ กัน

คุณสมบัตินี้กำหนดวิธีที่ Explosion จะโต้ตอบกับ Terrain มันเป็นค่า Enum.ExplosionType และสามารถตั้งค่าเป็นหนึ่งในสามตัวเลือกได้

  • NoCraters - การระเบิดจะไม่สร้างความเสียหายต่อพื้นที่
  • หลุมภูเขาไฟ - การระเบิดจะสร้างหลุมภูเขาไฟในพื้นที่
  • CratersAndDebris - ซ้ำซ้อน ทำงานเหมือนกับ Craters

หาก ExplosionType ถูกตั้งค่าให้สร้างหลุมใน Terrain รัศมีของหลุมจะเท่ากับประมาณ Explosion.BlastRadiusภูเขาไฟถูกสร้างขึ้นในวัสดุทั้งหมด Terrain ที่ไม่ใช่น้ําขนาดของหลุมอุกาบาตไม่ได้รับอิทธิพลจากวัสดุ แม้ว่าวัสดุบางอย่างจะสร้างขอบหยาบกว่าวัสดุอื่น ๆ

ตัวอย่างโค้ด

ตัวอย่างโค้ดนี้รวมถึงตัวอย่างวิธีที่คุณสมบัติ Explosion.ExplosionType สามารถใช้เพื่อหยุดการระเบิดที่อาจทำให้พื้นที่เสียหายขอแนะนำให้ตั้งประเภทการระเบิดเป็น NoCraters ที่จุดเกิดเหตุการระเบิด แต่ถ้าไม่สะดวกโค้ดด้านล่างจะทำงาน

หยุดการระเบิดที่ทำให้พื้นที่เสียหาย

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 สตัดของตำแหน่งการระเบิด

ผลกระทบของการระเบิดเป็นทันทีซึ่งหมายความว่าแม้ว่าตำแหน่งของการระเบิดจะสามารถเปลี่ยนแปลงได้หลังจากที่กำหนดแล้ว ก็ไม่สามารถส่งผลกระทบต่อพื้นที่ที่แตกต่างกันได้เมื่อการระเบิดถูก 'จุดระเบิด' ในไม่ช้าหลังจากผู้ปกครองไปยังลูกหลานของ Workspace มันจะไม่ทำอีกครั้งในบางกรณีเอฟเฟกต์ภาพของการระเบิดจะเคลื่อนที่ แต่มันจะไม่มีผล

ด้วยเหตุผลนี้จึงควรสร้างการระเบิดใหม่หากผู้พัฒนาต้องการให้การระเบิดปรากฏในตําแหน่งที่แตกต่าง

ตัวอย่างโค้ด

ตัวอย่างโค้ดนี้รวมถึงบรรทัดสั้นที่สร้างการระเบิดขนาดใหญ่ในเกมที่ 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

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 ของมัน ส่งคืนส่วนที่โจมตีพร้อมกับระยะห่างของส่วนจาก Explosion.Position

โปรดทราบว่าผลกระทบของ ไม่ถูกรบกวนโดยสิ่งกีดขวาง ซึ่งหมายความว่าส่วนที่ถูกปกป้องด้วยส่วนอื่นจะยังคงถูกโจมตีแม้ว่าส่วนที่ถูกปกป้องด้านหลังจะถูกยึดไว้ก็ตาม

อีเวนต์นี้จะยังจะยิงเมื่อ Explosion.BlastPressure เท่ากับศูนย์ซึ่งหมายความว่านักพัฒนาสามารถโปรแกรมพฤติกรรมที่กำหนดเองสำหรับการระเบิดโดยการลบอิทธิพลของการระเบิดบน BaseParts และ Terrain

โปรดทราบว่าอีเวนต์นี้จะยิงสำหรับทุก BasePart การโจมตีซึ่งหมายความว่ามันสามารถยิงหลายครั้งสำหรับตัวละครผู้เล่นเดียวกัน (เนื่องจากตัวละคร Model ประกอบด้วยส่วนหลายส่วน)ด้วยเหตุผลนี้เมื่อจัดการกับความเสียหายที่กําหนดเองโดยใช้เหตุการณ์ Explosion.Hit จึงเป็นที่แนะนําให้ดําเนินการตรวจสอบเพื่อดูว่าตัวละครถูกโจมตีโดย Explosion แล้วหรือยัง

พารามิเตอร์

part: BasePart

การโจมตี 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)