Explosion
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
การระเบิดใช้ความรุนแรงกับ BaseParts ภายในการระเบิดของการระเบิ
หาก Explosion มีความสัมพันธ์อยู่ที่ไหนก็ได้ในโมเดลข้อมูลขณะที่ประสบการณ์กำลังดำเนินการ มันจะทันทีติดตั้งและ
หมายเหตุว่า Explosion ต้องเป็นลูกหลานของ Workspace สำหรับให้วิดีโอการระเบิดและผลกระทบทางกายภาพ/ความเสียหายมีผล
เอฟเฟ็กต์ระเบิด
Humanoids ถูกฆ่าโดยระเบิดเนื่องจากการระเบิดทำให้ตัวละคร Model หัวหน้าข้อเท้าถูกพัง การเป็นพ่อของ ForceField จะปกป้องเด็กทั้งหมดจากการฆ่า
หากคุณไม่ต้องการให้มีข้อต่อระหว่าง BaseParts เพื่อให้แตก หรือคุณต้องการใช้สูตรของคุณเองสำหรับกา
การระเบิดยังสามารถกำหนดให้เสียหาย Terrain โดยสร้างหลุมดํา ตามที่กำหนดโดยประเภท ExplosionType ผ่านคุณสมบัติ
หมายเหตุว่าผลกระแทกจะไม่ได้รับการปรับปรุงโดยอุปสรรคจึงหมายถึงว่าผลกระแทกของชิ้นส่วน / พื้นผิวหลังอื่นจะยังคงได้รับผลกระทบ
ตัวอย่างโค้ด
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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
สรุป
คุณสมบัติ
ใช้เพื่อกำหนดจำนวนแรงที่ใช้กับ BaseParts ที่จับได้ใน Explosion.BlastRadius
สมบัตินี้กำหนดรัศมีของ Explosion ใน studs รัศมีนี้กำหนดพื้นที่ของผลกระทบของระเบิด ไม่ใช่ขนาดของวิดีโอระเบิด
ใช้เพื่อตั้งค่าอัตราส่วนของ Explosion.BlastRadius ระหว่าง 0 และ 1 ในขณะที่ทุกส่วนจะถูกทำลาย อะไรนอกเหนือขอบเขตนี้จะมีแค่ Explosion เท่านั้นที่ใช้กับมัน
สมบัตินี้กำหนดวิธีการที่ Explosion จะใช้งานกับ Terrain โดยใช้เพื่อตั้งค่าว่าการระเบิดจะสร้างความเสียหายให้กับพื้นผิวหรือไม่ ใช้เพื่อตั้งค่าว่าการระเบิดจะสร้างความเสียหายให้
คุณสมบัตินี้คือตำแหน่งศูนย์กลางของ Explosion มันถูกกำหนดในพื้นที่โลกและไม่ได้รับผลกระทบจากพ่อของ Explosion
มีค่าระหว่าง 0 และ 1 ที่ควบคุมความเร็วของเอฟเฟ็กต์อนุภาค
สมบัตินี้กำหนดว่าจะแสดงผลลัพธ์ทางสายตาของ Explosion หรือไม่
อีเวนต์
เปิดเมื่อ Explosion ตี Class.BasePart ภายใน BasePart ของมัน ส่งคืนชิ้นส่วนที่ตีพร้อมกับระยะทางของชิ้นส่วนจาก Explosion.BlastRadius
คุณสมบัติ
BlastPressure
ใช้เพื่อกำหนดจำนวนแรงที่ใช้กับ BaseParts ที่จับได้ใน Explosion.BlastRadius
ตอนนี้ระดับความเร่งที่ใช้ไม่ได้แตกต่างกันตามระยะทางจาก Explosion.Position หรือไม่ ได้รับการแนบมาจะเร่งเท่ากันออกจากด่านหน้าโดยไม่เป็นไปตามระยะทางที่พวกเขาให้ไว้ ภายในรัศ
ความดันสามารถกำหนดความเร่งของชิ้นส่วนเนื่องจากการระเบิด มันไม่ได้กำหนดว่าข้อต่อจะถูกทำลายมากแค่ไหน เมื่อ Explosion.DestroyJointRadiusPercent เท่ากับ 1
BlastPressure ไม่ได้ระบุจำนวนเงินของความเสียหายที่ให้กับ Terrain นอกจากนี้ BlastPressure ที่ให้นั้นยิ่งใหญ่กว่า 0 และ Class.Explosion.Explosion
การตั้งค่า 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.
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 ใน studs สมบัตินี้ยอมรับค่าใด ๆ ระหว่าง 0 และ 100
รัศมีนี้กำหนดพื้นที่ของผลกระแทกไม่ใช่ขนาดของวิดีโอของ Blast รัศมีขนาดของวิดีโอของ Blast จะเท่ากันไม่ว่าจะเป็น BlastRadius (แม้ว่า BlastRadius จะเป็น 0)
BaseParts ภายใน BlastRadius จะได้รับผลกระทบจากการระเบิด ซึ่งหมายถึง หาก Class.Explosion.BlastPress
BaseParts ถูกพิจารณาใน Explosion.BlastRadius แม้ว่าพวกเขาจะอยู่ในระยะไกล
ตัวอย่างโค้ด
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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 จ
สมบัตินี้ช่วยให้ผู้พัฒนาสามารถทำ Explosions 'non-lethal' ให้กับ Humanoids โดยการตั้ง DestroyJointRadiusPercent เป็น 0 ซึ่งหมายความว่าข้อต่อปลายจ
ตัวอย่างโค้ด
This sample includes an example of how Explosions can be made non lethal to player characters.
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.
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 มันเป็นข้อมูลรายการ สามารถกำหนดได้หนึ่งในสามตัวเลือก
- NoCraters - ระเบิดจะไม่ทำลายพื้นที่
- หลุมดํา - ระเบิดจะสร้างหลุมดําในภาพนี้
- CratersAndDebris - รอบคอบ, เหมือนกับ Craters
หากการตั้งค่า ExplosionType ได้รับการตั้งค่าใน Terrain รัศมีของร่อนจะอยู่ที่ประมาณเท่าของ Explosion.BlastRadius ร่อนจะถูกสร้างขึ้นใน
ตัวอย่างโค้ด
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.
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 สตัดของตำแหน่งระเบิด
ผลกระทบของการระเบิดเป็นทันที ซึ่งหมายความว่าแม้ว่าตำแหน่งของการระเบิดจะเปลี่ยนแปลงได้หลังจากที่มันถูกติดตั้ง มันจะไม่ส่งผลกระทบต่อพื้นที่สอ
ด้วยเหตุผลนี้จึงจะต้องสร้างการระเบิดใหม่หากผู้พัฒนาต้องการให้การระเบิดปรากฏในตำแหน่งที่แตกต่างกัน
ตัวอย่างโค้ด
This code sample includes a brief snippet that creates a large explosion in the game at 0, 10, 0.
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.
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 ตี Class.BasePart ภายใน BasePart ของมัน ส่งคืนชิ้นส่วนที่ตีพร้อมกับระยะทางของชิ้นส่วนจาก Explosion.BlastRadius
หมายเหตุว่าผลของ Explosion ไม่ได้รับการรบกวนโดยอุปสรรค, นี่หมายถึงว่าผู้ชิดอยู่หลังอื่น ๆ จะยังคงโดนตี, แม้ว่า BasePart ที่พวกเขาโดนแนบมัดจะติดอยู่
เหตุการณ์นี้จะยังเกิดขึ้นเมื่อ Explosion.BlastPressure เท่ากับ zero ซึ่งหมายความว่าผู้พัฒนาสามารถโปรแกรมพฤติกรรมของตัวเองสำหรับการระเบิดโดยการลบผลกระทบ
หมายเหตุว่าเหตุการณ์นี้จะเกิดขึ้นทุกๆ BasePart ที่ถูกตี ซึ่งหมายความว่ามันสามารถเกิดขึ้นได้หลายครั้งสำ
พารามิเตอร์
ระยะทางจากการโจมตีจาก 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.
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)