ForceField

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

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

A สนามพลัง ปกป้อง Humanoid จากการได้รับความเสียหายที่เกิดจากวิธี Humanoid:TakeDamage() และปกป้อง BaseParts จากการที่ข้อต่อของพวกเขาถูกทำลายเนื่องจาก Explosionสนามแรงดึงใหม่ ForceField จะถูกสร้างเมื่อตัวละครเกิดบน SpawnLocation และคุณสมบัติ SpawnLocation.Duration มีมากกว่าศูนย์

ความเสียหายและข้อต่อ

A สนามพลัง มีอิทธิพลต่อตัวอย่างที่เป็นพ่อของมันเมื่อถูกผูกกับ Model จะปกป้องทั้งหมดของ BaseParts ที่ลดลงจากโมเดลนั้นหากเป็นลูกของ BasePart ส่วน ส่วนจะได้รับการป้องกันเฉพาะถ้าทั้งส่วนและส่วนที่เชื่อมโยงกับมันยังมี ฟอร์ซฟิลด์ ForceField ปกป้อง Humanoids จากความเสียหายที่เกิดจากวิธี Humanoid:TakeDamage() เท่านั้นมนุษย์ยังสามารถได้รับความเสียหายโดยการตั้งค่า Humanoid.Health โดยตรงด้วยเหตุผลนี้จึงแนะนำให้คุณใช้ Humanoid:TakeDamage() เพื่อกำหนดความเสียหายในขณะที่คำนึงถึงการป้องกันฟิลด์แรง

การแสดงภาพ

เมื่อ ForceField.Visible ถูกตั้งค่าเป็นจริง จะสร้างเอฟเฟกต์อนุภาค จํานวนกฎกำหนดว่าเอฟเฟกต์นี้จะถูกปล่อยจากที่ใด:

  • เมื่อผู้ปกครองไปยัง Model หากโมเดลมี Humanoid ที่เรียกว่า Humanoid ที่มี Humanoid.RigType ตั้งค่าเป็น R15 ผลกระทบจะถูกส่งออกจากส่วนที่เรียกว่า UpperTorso มิฉะนั้นผลจะถูกปล่อยออกจากส่วนที่เรียกว่า ลําตัว * เมื่อถูกถ่ายโอนไปยัง BasePart ผลจะถูกปล่อยออกจากส่วน BasePart.Position

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

This code sample includes a function that will give a Player a ForceField for a specific duration.

ForceField Instantiation

local Players = game:GetService("Players")
local FORCE_FIELD_DURATION = 15
local function giveForcefield(player, duration)
local character = player.Character
if character then
local forceField = Instance.new("ForceField")
forceField.Visible = true
forceField.Parent = character
if duration then
task.delay(duration, function()
if forceField then
forceField:Destroy()
end
end)
end
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(_character)
giveForcefield(player, FORCE_FIELD_DURATION)
end)
end
Players.PlayerAdded(onPlayerAdded)

คุณสมบัติ

Visible

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

กำหนดว่าจะมีเอฟเฟกต์อนุภาค ForceField หรือไม่การตั้งค่านี้เป็น false ทำให้คุณสามารถแทนที่เอฟเฟกต์อนุภาคเริ่มต้นด้วยเอฟเฟกต์ที่กําหนดเองตามที่แสดงในตัวอย่างโค้ดต่อไปนี้

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

This sample includes a function that will replace the default ForceField particle effect with an effect using ParticleEmitters that can be modified by the developer.

Custom ForceField Effect

local Players = game:GetService("Players")
local FORCE_FIELD_DURATION = 15
local function createCustomForcefield(player, duration)
local character = player.Character
if character then
local humanoid = character:FindFirstChild("Humanoid")
if humanoid then
-- find the torso
local torsoName = humanoid.RigType == Enum.HumanoidRigType.R15 and "UpperTorso" or "Torso"
local torso = character:FindFirstChild(torsoName)
if torso then
-- create a forcefield
local forceField = Instance.new("ForceField")
forceField.Visible = false -- not visible
-- create a particle effect
local particleEmitter = Instance.new("ParticleEmitter")
particleEmitter.Enabled = true
particleEmitter.Parent = torso
-- listen for the forcefield being removed
forceField.AncestryChanged:Connect(function(_child, parent)
if not parent then
if particleEmitter and particleEmitter.Parent then
particleEmitter:Destroy()
end
end
end)
-- parent the forcefield and set it to expire
forceField.Parent = character
if duration then
task.delay(duration, function()
if forceField then
forceField:Destroy()
end
end)
end
end
end
end
end
local function onPlayerAdded(player)
player.CharacterAdded:Connect(function(_character)
createCustomForcefield(player, FORCE_FIELD_DURATION)
end)
end
Players.PlayerAdded(onPlayerAdded)

วิธีการ

อีเวนต์