BasePart
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
BasePart เป็นคลา
สำหรับข้อมูลเกี่ยวกับวิธีการที่ BaseParts ถูกรวมเป็นกลุ่มเป็นตัวเรียบงอกของการจำลองความแข็งแกร่ง ดู การประกอบ
มีวัตถุหลายชนิดที่ใช้งานกับ BasePart (นอกเหนือจาก Terrain ) รวมถึง:
- หลาย BaseParts อาจถูกรวมอยู่ใน Model และย้ายได้ในเวลาเดียวกันโดยใช้ PVInstance:PivotTo() ดู 2>โมเดล2> .
- A SurfaceGui เรนเดอร์ Class.GuiObject|GuiObjects บนหน้าของชิ้นส่วน ดู GuiObjects .
- Attachments สามารถเพิ่มไปยัง BasePart เพื่อระบุ CFrames ส่วนเกี่ยวกับส่วน นี้มักจะใช้โดยวัตถุ 0>Class.Limit
- ParticleEmitter วัตถุปล่อยอนุภาคในปริมาณที่เท่ากันในพื้นที่ของ BasePart ที่พวกเขาเป็นลูกของมัน ดูที่ ผู้ปล่อยอนุภาค
สรุป
คุณสมบัติ
กำหนดว่าชิ้นส่วนนั้นเป็นของเหนียวตามธรรมชาติหรือไม่
ความเร็วมุมของการประกอบของชิ้นส่วน
ศูนย์กลางของพลังงานในการประกอบของชิ้นส่วนในอวกาศ
ความเร็วที่เฉียบขาดของการประกอบของชิ้นส่วน
พลังงานทั้งหมดของการประกอบของชิ้นส่วน
อ้างอิงถึงส่วนรากของการประกอบ
กำหนดประเภทของพื้นผิวสำหรับหน้าด้านหลังของชิ้นส่วน (+Z ทิศทาง)
กำหนดประเภทของพื้นผิวสำหรับด้านล่างของชิ้นส่วน (-Y ทิศทาง)
กำหนดสีของชิ้นส่วน
กำหนดตำแหน่งและทิศทางของ BasePart ในโลก
กำหนดว่าชิ้นส่วนอาจชนกับชิ้นส่วนอื่น
กำหนดว่าจะใช้การสอบถามข้อมูลทางอาณาเขตในขั้นตอนการประมวลผลหรือไม่
กำหนดว่า Touched และ TouchEnded เหตุการณ์จะเกิดขึ้นบนชิ้นส่วน
กำหนดว่าจะมีเงาหรือไม่มีเงา
อธิบายตำแหน่งกลางของมวลของชิ้นส่วน
อธิบายชื่อกลุ่มความสามัคคีของชิ้นส่วน
กำหนดสีของชิ้นส่วน
ระบุลักษณะทางกายภาพปัจจุบันของชิ้นส่วน
กำหนดสมบัติภาพทางกายภาพหลายอย่างของชิ้นส่วน
ใช้เพื่อเปิดใช้งานหรือปิดการใช้งานแรงโน้มถ่วงบนชิ้นส่วนและการประกอบ
ขนาดทางกายภาพจริงของ BasePart ตามที่เครื่องจักรฟิสิกส์มองว่า
กำหนดประเภทของพื้นผิวสำหรับหน้าผากของชิ้นส่วน (-Z ทิศทาง)
กำหนดประเภทของพื้นผิวสำหรับหน้าซ้ายของชิ้นส่วน (-X ทิศทาง)
กำหนดตัวคูณสำหรับ BasePart.Transparency ที่มองเห็นได้เฉพาะลูกค้าท้องถิ่นเท่านั้น
กำหนดว่าจุดส่วนหนึ่งสามารถเลือกได้ใน Studio
อธิบายปริมาณของชิ้นส่วน ผลิตภัณฑ์ของความหนาแน่นและปริมาณ
กำหนดว่าส่วนหนึ่งมีส่วนร่วมกับพลังงานทั้งหมดหรือความต้องการในตัวเองของร่างกายที่แข็งแกร่ง
กำหนดคุณสมบัติและคุณสมบัติทางกายภาพปกติของชิ้นส่วน
ชื่อของ MaterialVariant
อธิบายการหมุนของชิ้นส่วนในโลก
ระบุค่าเฉลี่ยของส่วนหมุนจาก Datatype.CFrame ของมัน
อธิบายตำแหน่งของชิ้นส่วนในโลก
เวลาตั้งแต่อัปเดตฟิสิกส์ครั้งล่าสุด
กำหนดว่าส่วนใดสะท้อนสกายบ็อกซ์ได้มาก
อธิบายการเปลี่ยนแปลงขนาดเล็กสุดที่อนุญาตโดยวิธีขยาย
อธิบายใบหน้าที่ส่วนหนึ่งอาจเปลี่ยนขนาด
กำหนดประเภทของพื้นผิวสำหรับด้านขวาของชิ้นส่วน (+X ทิศทาง)
กฎหลักในการกำหนดราก้อนของการประกอบการ
การหมุนของส่วนในองศาสำหรับสามแกน
กำหนดความสูงของชิ้นส่วน (ความสูง) ความกว้าง (ความกว้าง) และความสูง (ความสูง)
กำหนดประเภทของพื้นผิวสำหรับหน้าด้านบนของชิ้นส่วน (+Y ทิศทาง)
กำหนดว่าส่วนหนึ่งสามารถมองเห็นได้มากเท่าไหร่ (คือสิ่งที่ผิดพลาดของความโปร่งใสของส่วน)
วิธีการ
ใช้แรงผลักแบบมุมเพื่อประกอบ
ใช้แรงผลักในการประยุกต์ใช้งานต่อวงจรที่ center of mass
ใช้แรงผลักไปยังการประกอบในตำแหน่งที่กำหนด
กลับว่าชิ้นส่วนสามารถชนกันได้หรือไม่
ตรวจสอบว่าคุณสามารถตั้งค่าเครือข่ายของบางส่วนได้หรือไม่
กลับตารางของชิ้นส่วนที่เชื่อมต่อกับวัตถุโดยประเภทของข้อต่อที่แข็งแกร่ง
กลับส่วนของร่วมหรือข้อจํากัดที่เชื่อมต่อกับส่วนนี้
กลับค่าของสมบัติสินค้า Mass
กลับผู้เล่นปัจจุบันที่เป็นเจ้าของเครือข่ายของส่วนนี้ หรือ zero ในกรณีของเซิร์ฟเวอร์
กลับ true หากเครื่องยนต์เกมตัดสินผู้สมัครเครือข่ายสำหรับส่วนนี้โดยอัตโนมัติ
กลับส่วนปูมของการรวบรวมของชิ้นส่วน
กลับตารางของ all BasePart.CanCollide ชิ้นส่วนที่เป็นส่วนหนึ่งกับส่วนนี้
กลับค่าความเร็วเส้นที่เป็นลินเนียมของการประกอบของชิ้นส่วนที่ให้ไว้ในตำแหน่งนี้เมื่อเปรียบเทียบกับตำแหน่งนี้
กลับ true หากวัตถุเชื่อมต่อกับส่วนที่จะรองรับมันในที่ (เช่น Anchored ส่วน) ยกเว้นกลับ false หากเป็นกรณีอื่น
เปลี่ยนขนาดของวัตถุเหมือนการใช้เครื่องมือขยายขนาดใน Studio
ตั้งผู้เล่นที่ให้เป็นเจ้าของเครือข่ายสำหรับส่วนนี้และส่วนที่เชื่อมต่ออื่น ๆ
ให้เครื่องมือเกมตัดสินใจได้อย่างไดนามิกว่าใครจะดูแลฟิสิกส์ของชิ้นส่วน (หนึ่งในลูกค้าหรือเซิร์ฟเวอร์)
- IntersectAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
สร้าง IntersectOperation ใหม่จากเหลี่ยมของผลิตภัณฑ์และอื่น ๆ ในค่าย่อที่ให้
- SubtractAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
สร้าง UnionOperation ใหม่จากส่วน โดยลบภูมิที่เป็นรูปสี่เหลี่ยมจากส่วนที่อยู่ในแผนที่ที่ให้
- UnionAsync(parts : Instances,collisionfidelity : Enum.CollisionFidelity,renderFidelity : Enum.RenderFidelity):Instance
สร้าง UnionOperation ใหม่จากส่วน รวมถึงภาพที่เป็นรูปร่างที่ครอบครองพื้นที่ส่วนในแผงที่ให้
รับ pivot ของ Class.PVInstance
แปลง PVInstance พร้อมกับบรรพบุรุษทั้งหมดของมัน PVInstances เพื่อให้ pivot ตอนนี้อยู่ที่ CFrame ที่กำหนด
อีเวนต์
เกิดขึ้นเมื่อชิ้นส่วนหยุดแตะอีกชิ้นส่วนในผลมาจากการเคลื่อนที่ทางกายภาพ
เกิดขึ้นเมื่อชิ้นส่วนสัมผัสกับอีกชิ้นส่วนในผลมาจากการเคลื่อนที่ทางกายภาพ
คุณสมบัติ
Anchored
สมบัติของการแนบ เป็นเกล็ด จะกำหนดว่าจะเป็นไปตามธรรมชาติหรือไม่ เมื่อเปิดใช้งาน สมบัติจะไม่เปลี่ยนตำแหน่งเนื่องจากแรงโน้มถ่วง การชนกันขอ
ส่วนที่แนบอาจยังคงย้ายได้โดยการเปลี่ยน CFrame หรือ Position และยังอาจมี AssemblyLinearVelocity แ
ในที่สุด หากชิ้นส่วนที่ไม่มีโครงสร้างถูกเชื่อมต่อกับชิ้นส่วนโดยตรงผ่านวัตถุเช่น Weld มันก็จะทำงานเชิญชูเช่นกัน หากชิ้นส่วนนั้นพัง มันอาจส่งผลให้ชิ้นส่ว
การเป็นเจ้าของเครือข่ายไม่สามารถตั้งได้ที่ส่วนที่แนบมา หากสถานะของส่วนที่แนบมาเปลี่ยนแปลงในเซิร์ฟเวอร์ สถานะเป็นเจ้าของเครือข่ายของส่วนนั้นจะได้รับผลกระทบ
ตัวอย่างโค้ด
This code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).
local part = script.Parent
-- Create a ClickDetector so we can tell when the part is clicked
local cd = Instance.new("ClickDetector", part)
-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
if part.Anchored then
-- When the part is anchored...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- When the part is unanchored...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- Toggle the anchored property
part.Anchored = not part.Anchored
-- Update visual state of the brick
updateVisuals()
end
-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:Connect(onToggle)
AssemblyAngularVelocity
เวกเตอร์ความเร็วมุมของส่วนประกอบนี้ มันเป็นอัตราการเปลี่ยนแปลงของตำแหน่งในรัศมีต่อวินาที
ความเร็ว각องเหลี่ยมเป็นเดียวกันทุกจุดของการประกอบ
การตั้งค่าความเร็วโดยตรงอาจนำไปสู่การเคลื่อนไหวที่ไม่เป็นจริง การใช้ Torque หรือ AngularVelocity ข้อจํากัด หรือใช้ BasePart:ApplyAngularImpulse() หากคุณต้องการการ
หากชิ้นส่วนเป็นของ โดยเซิร์ฟเวอร์มีขนาดใหญ่เกินไ
AssemblyCenterOfMass
ตําแหน่งที่คํานวณโดย mass และ position ของชิ้นส่วนทั้งหมดในการประกอบ
หากการประกอบมีส่วนที่แนบมัด ส่วนกลางของมวลการประกอบจะเป็นศูนย์กลางของมวลการประกอบ และการประกอบจะมีมวลการประกอบที่ไม่มีที่สิ้นสุด
การรู้จุดศูนย์กลางของมวลชนสามารถช่วยให้การประกอบรวมมีความเสถียรได้ การใช้แรงผลักไปยังศูนย์กลางของมวลชนจะไม่ทำให้เกิดความเร่งมุม เท่านั้น การประกอบรวมที่มีศูนย์กลางต่ำจะมีเวลาที่ดี
AssemblyLinearVelocity
ベクトルความเร็วที่เป็นเส้นทางของการประกอบของส่วนนี้ มันเป็นอัตราการเปลี่ยนแปลงในตำแหน่งของการประกอบของส่วนนี้ center of mass ในตันต่อวินาที
หากคุณต้องการทราบความเร็วที่อยู่ในจุดอื่นนอกจากศูนย์กลางของการประกอบของการประกอบ, ใช้ BasePart:GetVelocityAtPosition() .
การตั้งค่าความเร็วโดยตรงอาจนำไปให้เป็นการเคลื่อนไหวที่ไม่สมจริง โดยใช้ VectorForce ข้อจํากัด หรือใช้ BasePart:ApplyImpulse() หากต้องการการเปลี่ยนแปลงที่รวดเร็ว
หากชิ้นส่วนเป็นของ โดยเซิร์ฟเวอร์มีขนาดใหญ่เกินไ
AssemblyMass
จํานวนเงินของมวลของทั้งหมดของ parts ในส่วนประกอบนี้จะไม่เป็นส่วนหนึ่งของการจัดการการประกอบ ส่วนที่เป็น Massless และไม่ใช่ส่วนหนึ่งของการจัด
หากการประกอบมีส่วนหนึ่งที่แนบมัดอยู่ การประกอบจะถูกพิจารณาว่าเป็นไปตามลำดับหนึ่ง ข้อจํากัด และปฏิสัมพันธ์ทางกายภาพอื่น ๆ ระหว่างการประกอบที่ไม่มีความแตกต่างกันอาจทําให้เกิดความไม่เส
AssemblyRootPart
สมบัตินี้แสดงถึง BasePart ที่เลือกอัตโนมัติเพื่อแทนที่ส่วนโครงของการประกอบ มันเป็นส่วนเดียวกันที่กลับมาเมื่อผู้พัฒนาเรียก GetRootPart()
ส่วนรากสามารถเปลี่ยนได้โดยการเปลี่ยน RootPriority ของชิ้นส่วนในการประกอบ
ชิ้นส่วนที่ทุกคนแชร์เดียวกันที่นี่คือการประกอบที่เดียวกัน
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับรากหัวโหม่ง โปรดดู การประกอบ
BackSurface
คุณสมบัติ BackSurface กำหนดประเภทของพื้นผิวที่ใช้สำหรับ +Z ทิศทางของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนวางอยู่ต่อหน้ากัน พวกเขาอาจสร้างช่องร่วมกันระหว่างพวกเขา หากกำหนดไว้ที่
ส่วนใหญ่ของ SurfaceTypes จะเรนเดอร์เนื้อผิวบนหน้าผิวหาก BasePart.Material ติดตั้งไว้ที่ Plastic บาง SurfaceTypes - Hinge, Motor และ SteppingMotor - จะเรนเดอร์ออร์แนมเมนต์ 3D แทน หากโ
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
BottomSurface
ลักษณะ BottomSurface กำหนดประเภทของพื้นผิวที่ใช้สำหรับ -D ทิศทางของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนวางอยู่ต่อหน้ากัน พวกเขาอาจสร้างการรวมกันระหว่างพวกเขา หากกำหนดไว้ที่มอเ
ส่วนใหญ่ของ SurfaceTypes จะเรนเดอร์เนื้อผิวบนหน้าผิวหาก BasePart.Material ติดตั้งไว้ที่ Plastic บาง SurfaceTypes - Hinge, Motor และ SteppingMotor - จะเรนเดอร์ออร์แนมเมนต์ 3D แทน หากโ
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
BrickColor
สมบัติสีของส่วนหนึ่งกำหนดสีของส่วนหนึ่ง หากส่วนหนึ่งมี BasePart.Material ให้สีใช้งานได้เมื่อเรนเดอร์เนื้อผ้า สำหรับข้อมูลเพิ่มเติมเกี่ยวก
ลักษณะทางสายตาของอื่นๆของชิ้นส่วนได้รับการกำหนดโดย BasePart.Transparency และ BasePart.Reflectance
ตัวอย่างโค้ด
This code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).
local part = script.Parent
-- Create a ClickDetector so we can tell when the part is clicked
local cd = Instance.new("ClickDetector", part)
-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
if part.Anchored then
-- When the part is anchored...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- When the part is unanchored...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- Toggle the anchored property
part.Anchored = not part.Anchored
-- Update visual state of the brick
updateVisuals()
end
-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:Connect(onToggle)
CFrame
สมบัติ CFrame ระบุตำแหน่งและทิศทางของ BasePart ในโลก มันทำงานเป็นตำแหน่งอ้างอิงในเชิงภาพที่เป็นเชิงอารียะ แต่ Class.BasePart.ExtentsCFrame|ExtentsCFrame
เมื่อการตั้งค่า CFrame บนส่วนหนึ่งอื่น ๆ ที่เข้าร่วมกับส่วนนั้นยังย้ายไปยังส่วนหนึ่ง แต่จะแนะนำให้ใช้ PVInstance:PivotTo() ผู้เล่น
ในขณะที่การตั้งค่า BasePart.Position จะย้ายชิ้นส่วนไปยังตำแหน่งที่แน่นอน BasePart.CFrame จะพยายามที่จะแก้ไขความสัมพันธ์ข
สำหรับการติดตามตำแหน่งเมื่อเป็นเรื่องของ CFrame ของชิ้นส่วน การใช้ Attachment อาจเป็นประโยชน์
ตัวอย่างโค้ด
This code sample demonstrates setting a part's CFrame in many different ways. It showcases how to create and compose CFrame values. It references a sibling part called "OtherPart" for demonstrating relative positioning.
local part = script.Parent:WaitForChild("Part")
local otherPart = script.Parent:WaitForChild("OtherPart")
-- Reset the part's CFrame to (0, 0, 0) with no rotation.
-- This is sometimes called the "identity" CFrame
part.CFrame = CFrame.new()
-- Set to a specific position (X, Y, Z)
part.CFrame = CFrame.new(0, 25, 10)
-- Same as above, but use a Vector3 instead
local point = Vector3.new(0, 25, 10)
part.CFrame = CFrame.new(point)
-- Set the part's CFrame to be at one point, looking at another
local lookAtPoint = Vector3.new(0, 20, 15)
part.CFrame = CFrame.lookAt(point, lookAtPoint)
-- Rotate the part's CFrame by pi/2 radians on local X axis
part.CFrame = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0)
-- Rotate the part's CFrame by 45 degrees on local Y axis
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0)
-- Rotate the part's CFrame by 180 degrees on global Z axis (note the order!)
part.CFrame = CFrame.Angles(0, 0, math.pi) * part.CFrame -- Pi radians is equal to 180 degrees
-- Composing two CFrames is done using * (the multiplication operator)
part.CFrame = CFrame.new(2, 3, 4) * CFrame.new(4, 5, 6) --> equal to CFrame.new(6, 8, 10)
-- Unlike algebraic multiplication, CFrame composition is NOT communitative: a * b is not necessarily b * a!
-- Imagine * as an ORDERED series of actions. For example, the following lines produce different CFrames:
-- 1) Slide the part 5 units on X.
-- 2) Rotate the part 45 degrees around its Y axis.
part.CFrame = CFrame.new(5, 0, 0) * CFrame.Angles(0, math.rad(45), 0)
-- 1) Rotate the part 45 degrees around its Y axis.
-- 2) Slide the part 5 units on X.
part.CFrame = CFrame.Angles(0, math.rad(45), 0) * CFrame.new(5, 0, 0)
-- There is no "CFrame division", but instead simply "doing the inverse operation".
part.CFrame = CFrame.new(4, 5, 6) * CFrame.new(4, 5, 6):Inverse() --> is equal to CFrame.new(0, 0, 0)
part.CFrame = CFrame.Angles(0, 0, math.pi) * CFrame.Angles(0, 0, math.pi):Inverse() --> equal to CFrame.Angles(0, 0, 0)
-- Position a part relative to another (in this case, put our part on top of otherPart)
part.CFrame = otherPart.CFrame * CFrame.new(0, part.Size.Y / 2 + otherPart.Size.Y / 2, 0)
CanCollide
CanCollide ตรวจสอบว่าชิ้นส่วนจะโต้ตอบกับชิ้นส่วนอื่นหรือไม่ เมื่อปิดใช้งาน ชิ้นส่วนอื่น ๆ สามารถผ่าน CanCollide ได้โดยไม่ต้องผ่านพลังงานฟิสิกส์ ส่วนประกอบที่ใช้สําหรับการตกแต่งมักจะ
หากชิ้นส่วนไม่ได้อยู่ภายใต้ BasePart.Anchored และมี CanCollide ปิด, มันอาจจะหลุดออกจากโลกนี้โดยสุดท้ายจะถูกทำลายโดย Workspace.FallenPartsDestroyHeight
เมื่อปิดการโดนาสามารถให้เหตุการณ์ BasePart.Touched (รวมทั้งอีเวนต์อื่น ๆ ที่แตะพวกเขา) เป็นเหตุการณ์ที่ยังคงเกิดขึ้นได้ (ด้วย BasePart.CanTouch )
สำหรับข้อมูลเพิ่มเติมเกี่ยวกับการชนกันโปรดดู การชนกัน
ตัวอย่างโค้ด
This code sample shows how a part can fade away when touched by a Humanoid then reappear a moment after to create a passable door.
-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()
CanQuery
CanQuery สามารถระบุได้ว่าชิ้นส่วนนั้นได้รับการพิจารณาในการดำเนินการข询ภาพลายเส้นหรือไม่ เช่น GetPartBoundsInBox หรือ
นอกเหนือจากสิ่งนี้, ยังเป็นไปได้ที่จะรวมออกรายการที่เป็นลูกหลานของรายการที่ให้ไว้ด้านล่างโดยใช้วัตถุ OverlapParams หรือ RaycastParams เมื่อเรียกใช้งานตัวคำถามทางพื้นที่
CanTouch
สมบัตินี้กำหนดว่า Class.BasePart.
หมายเหตุว่าเหตุการณ์นี้สามารถกำหนดได้เพื่อเคารพ กลุ่มความร่วมการชน ผ่านสมบัติ Workspace.TouchesUseCollisionGroups หาก true ส่วนในกลุ่มที่ไม่มีความร่วมก
ประสิทธิภาพ
มีการประสิทธิภาพเล็กน้อยในชิ้นส่วนที่มีทั้ง CanTouch และ CanCollide ตั้งไว้ท
CastShadow
กำหนดว่าจะมีเงาหรือไม่มีเงา
หมายเหตุว่าคุณสมบัตินี้ไม่ได้ออกแบบมาสําหรับประสิทธิภาพ คุณควรใช้มันเฉพาะในชิ้นส่วนที่คุณต้องการซ่อนเงาที่ผลิตโดยชิ้นส่วนนั้น การปิดใช้งานคุณสมบัตินี้สําหรับชิ้นส่วนบาง
CenterOfMass
สมบัติของศูนย์อธิบายตำแหน่งศูนย์กลางของมวลของชิ้นส่วน หากเป็นการรวมการแสดงผลของชิ้นส่วนหนึ่งหรือหลายชิ
CollisionGroup
สมบัติ CollisionGroup ระบุชื่อกลุ่มความเข้ากันของชิ้นส่วน (สูงสุด 100 ตัวอักษร) ชิ้นส่วนเริ่มต้นในกลุ่มปกติที่มีชื่อว่า "Default" ค่านี้ไม่สามารถว่างเปล
แม้ว่าสิ่งนี้เองจะไม่เป็นรีพลิคท์ แต่เครื่องยนต์จะเรียกร้องค่าผ่านตัวอื่นของสิ่งส่วนตัวเพื่อแก้ปัญหาความถูกกลับรุ่น
ตัวอย่างโค้ด
This example demonstrates one basic use of collision groups. It assigns BallPart to "CollisionGroupBall" and DoorPart to "CollisionGroupDoor", then makes the two groups non-collidable using PhysicsService:CollisionGroupSetCollidable().
local PhysicsService = game:GetService("PhysicsService")
local collisionGroupBall = "CollisionGroupBall"
local collisionGroupDoor = "CollisionGroupDoor"
-- Register collision groups
PhysicsService:RegisterCollisionGroup(collisionGroupBall)
PhysicsService:RegisterCollisionGroup(collisionGroupDoor)
-- Assign parts to collision groups
script.Parent.BallPart.CollisionGroup = collisionGroupBall
script.Parent.DoorPart.CollisionGroup = collisionGroupDoor
-- Set groups as non-collidable with each other and check the result
PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor, false)
print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor)) --> false
Color
สี The ระบุสีของชิ้นส่วน หากชิ้นส่วนมีสี BasePart.Material นี่จะกำหนดสีที่ใช้เมื่อเรนเดอร์เนื้อผ้า หากสีนี้ถูกตั้งค่าไว้, BasePart.BrickColor จะใช้สีที่ใกล้เคียงท
ลักษณะทางสายตาของอื่นๆของชิ้นส่วนได้รับการกำหนดโดย BasePart.Transparency และ BasePart.Reflectance
ตัวอย่างโค้ด
This code sample colors a player's entire character based on how much health they have. It generates a color based on their max health, then sets the color properties of objects within their character, removing any extra objects.
-- Paste into a Script within StarterCharacterScripts
-- Then play the game, and fiddle with your character's health
local char = script.Parent
local human = char.Humanoid
local colorHealthy = Color3.new(0.4, 1, 0.2)
local colorUnhealthy = Color3.new(1, 0.4, 0.2)
local function setColor(color)
for _, child in pairs(char:GetChildren()) do
if child:IsA("BasePart") then
child.Color = color
while child:FindFirstChildOfClass("Decal") do
child:FindFirstChildOfClass("Decal"):Destroy()
end
elseif child:IsA("Accessory") then
child.Handle.Color = color
local mesh = child.Handle:FindFirstChildOfClass("SpecialMesh")
if mesh then
mesh.TextureId = ""
end
elseif child:IsA("Shirt") or child:IsA("Pants") then
child:Destroy()
end
end
end
local function update()
local percentage = human.Health / human.MaxHealth
-- Create a color by tweening based on the percentage of your health
-- The color goes from colorHealthy (100%) ----- > colorUnhealthy (0%)
local color = Color3.new(
colorHealthy.R * percentage + colorUnhealthy.r * (1 - percentage),
colorHealthy.G * percentage + colorUnhealthy.g * (1 - percentage),
colorHealthy.B * percentage + colorUnhealthy.b * (1 - percentage)
)
setColor(color)
end
update()
human.HealthChanged:Connect(update)
CurrentPhysicalProperties
ค่าโครงสร้างทางกายภาพปัจจุบันบ่งชี้คุณสมบัติทางกายภาพปัจจุบันของชิ้นส่วน คุณสามารถตั้งค่าค่าผสมที่กำหนดเองสำหรับคุณสมบัติทางกายภาพของแต่ละชิ้นส่วนได้ วัสดุ
- คุณสมบัติทางกายภาพของชิ้นส่วน
- คุณสมบัติทางกายภาพของวัสดุที่กำหนดเองของชิ้นส่วน
- คุณสมบัติทางกายภาพของวัสดุจะเปลี่ยนแปลงไปเมื่อวัสดุของชิ้นส่วน
- คุณสมบัติทางกายภาพปกติของวัสดุของชิ้นส่วน
CustomPhysicalProperties
CustomPhysicalProperties ช่วยให้คุณปรับแต่งลักษณะทางกายภาพต่างๆ ของ Part เช่น ความหนาแน่น ความเปลี่ยนแปลง และความยืดหยุ่น
หากเปิดใช้งานสิ่งนี้จะช่วยให้คุณกำหนดคุณสมบัติทางกายภาพเหล่านี้ หากปิดใช้งานสิ่งนี้จะกำหนดคุณสมบัติทางกายภาพเหล่านี้โดยผ่าน BasePart.Material ของส่วน
ตัวอย่างโค้ด
This code sample demonstrates how to set the CustomPhysicalProperties property of a part.
local part = script.Parent
-- This will make the part light and bouncy!
local DENSITY = 0.3
local FRICTION = 0.1
local ELASTICITY = 1
local FRICTION_WEIGHT = 1
local ELASTICITY_WEIGHT = 1
local physProperties = PhysicalProperties.new(DENSITY, FRICTION, ELASTICITY, FRICTION_WEIGHT, ELASTICITY_WEIGHT)
part.CustomPhysicalProperties = physProperties
EnableFluidForces
เมื่อเปิดใช้งาน และเมื่อ Workspace.FluidForces เปิดใช้งาน ส่งผลให้มอเตอร์ฟิสิกส์คำนวณแรงโน้มถ่วงบน BasePart นี้
FrontSurface
สมบัติที่พื้นผิวหน้าใช้สำหรับ -D ทิศทางของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนถูกวางต่อกัน พวกเขาอาจสร้างการรวมกันระหว่างพวกเขา หากการตั้งค่าสู่ มอเตอร์ สมบัติที่ว่า
ส่วนใหญ่ของ SurfaceTypes เรนเดอร์เนื้อผิวบนหน้าผาหาก BasePart.Material ตั้งค่าเป็น Plastic บาง SurfaceTypes รวมทั้ง Hinge, Motor และ SteppingMotor เรนเดอร์ออร์นาเมนต์ 3D แทน หากคุณเ
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
LeftSurface
คุณสมบัติ LeftSurface กำหนดประเภทของพื้นผิวที่ใช้สำหรับ -X ทิศทางของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนวางอยู่ต่อหน้ากัน พวกเขาอาจสร้างข้อต่อระหว่างพวกเขา หากการตั้งค่านี้เป็
ส่วนใหญ่ของ SurfaceTypes เรนเดอร์เนื้อผิวบนหน้าผาหาก BasePart.Material ตั้งค่าเป็น Plastic บาง SurfaceTypes รวมทั้ง Hinge, Motor และ SteppingMotor เรนเดอร์ออร์นาเมนต์ 3D แทน หากคุณเ
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
LocalTransparencyModifier
สมบัติทรัพย์ LocalTransparencyModifier คือตัวคูณของ BasePart.Transparency ที่เฉพาะสำหรับลูกค้าท้องถิ่นเท่านั้น มันไม่เกิดขึ้นจากลูกค้าไปยังเซิร์ฟเ
สมบัติสินค้านี้จะเปลี่ยนแปลงความโปร่งใสของชิ้นส่วนในพื้นที่โดยใช้สูตรต่อไปนี้ผ่านผลลัพธ์ที่ปรับแต่งระหว่าง 0 และ 1
clientTransparency = 1 - ((1 - part.Transparency) * (1 - part.LocalTransparencyModifier))
<tbody><tr><td>0.5</td><td>0</td><td>0.5</td><td>0.5</td></tr><tr><td>0.5</td><td>0.25</td><td>0.5</td><td>0.625</td></tr><tr><td>0.5</td><td>0.5</td><td>0.5</td><td>0.75</td></tr><tr><td>0.5</td><td>0.75</td><td>0.5</td><td>0.875</td></tr><tr><td>0.5</td><td>1</td><td>0.5</td><td>1</td></tr></tbody>
ความโปร่งใส | ตัวแก้ไขความโปร่งใสท้องถิ่น | ความโปร่งใสข้างเซิร์ฟเวอร์ | ความโปร่งใสข้างลูกค้า |
---|
Locked
สถิติล็อคจะกำหนดว่า part (หรือ model ที่อยู่ใน) สามารถเลือกใน Roblox Studio โดยคลิกที่มัน สถิตินี้จะเปิดใช้งานบนส่วนของ
ตัวอย่างโค้ด
This code sample uses the concept of recursion to unlock all parts that are a descendant of a model.
-- Paste into a Script within a Model you want to unlock
local model = script.Parent
-- This function recurses through a model's heirarchy and unlocks
-- every part that it encounters.
local function recursiveUnlock(object)
if object:IsA("BasePart") then
object.Locked = false
end
-- Call the same function on the children of the object
-- The recursive process stops if an object has no children
for _, child in pairs(object:GetChildren()) do
recursiveUnlock(child)
end
end
recursiveUnlock(model)
Mass
Mass เป็นสมบัติสัมพันธ์ที่อ่านเท่านั้นที่อธิบายคุณสมบัติของปริมาณและความหนาแน่นของชิ้นส่วน มันจะถูกส่งโดยคุณสมบัติ GetMass
- ความหนาแน่นของชิ้นส่วนจะถูกกำหนดโดย Material หรือ CustomPhysicalProperties หากมีการระบุ
Massless
ถ้าคุณสมบัตินี้เปิดใช้งานได้, the BasePart จะไม่มีส่วนร่วมในพลังงานทั้งหมดหรือความเป็นกลางของการประกอบของมันเมื่อเชื่อมต่อกับอีกส่วนที่มีพลังงาน
หากชิ้นส่วนเป็นส่วนรากของตัวเองตาม AssemblyRootPart จะไม่ได้รับการเพิกเฉยสำหรับส่วนนั้น และยังคงมีส่วนร่วมกับความสามัคคีของการประกอบของมันเช่นเด
นี่อาจเป็นประโยชน์สำหรับสิ่งเหล่านี้เช่นอุปกรณ์เสริมติดตั้งบนยานพาหนะที่คุณไม่ต้องการส่งผลการจัดการของรถหรือเมชรุกขนาดมากขึ้นที่เชื่อมติดกับเมชรุกง่าย
ดูเพิ่มเติมที่ การประกอบการกับกัน บทความที่อธิบายว่าอะไหล่รากเป็นอย่างไรและจะใช้งานได้อย่างไร
Material
สมบัติทรัพย์วัสดุช่วยให้ผู้สร้างติดตั้งค่าของวัสดุชิ้นส่วนและสมบัติทรัพย์ทางกายภาพ (ในกรณีที่ BasePart.CustomPhysicalProperties ไม่ได้ถูกติดตั้ง) วัสดุ
การตั้งค่าสมบัติทรัพย์นี้จะใช้คุณสมบัติทางกายภาพที่เป็นเอกลักษณ์ของวัสดุ โดยปกติ DiamondPlate เป็นวัสดุที่หนาแน่นมากขณะที่ Wood เป็นวัสดุเบา ความหนาแน่นของชิ้นส่วนจะกำหนดว่ามันจะลอ
วัสดุแก้วเปลี่ยนพฤติกรรมการเรนเดอร์ในการตั้งค่ากราฟิกที่เหมาะสม มันใช้ความสะท้อนแสง (คล้ายกับ BasePart.Reflectance และความผิดพลาดในมุมมอง ผลลัพธ์
ตัวอย่างโค้ด
This code sample will allow a part to be clicked to toggle its anchored property. When toggled, the visual appearance of the part is updated (red means anchored, yellow means free).
local part = script.Parent
-- Create a ClickDetector so we can tell when the part is clicked
local cd = Instance.new("ClickDetector", part)
-- This function updates how the part looks based on its Anchored state
local function updateVisuals()
if part.Anchored then
-- When the part is anchored...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- When the part is unanchored...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- Toggle the anchored property
part.Anchored = not part.Anchored
-- Update visual state of the brick
updateVisuals()
end
-- Update, then start listening for clicks
updateVisuals()
cd.MouseClick:Connect(onToggle)
MaterialVariant
ระบบค้นหา MaterialVariant รายการด้วยชื่อ MaterialVariant อินสแตนซ์BasePart.Material พิมพ์
Orientation
สมบัติของคุณคือสิ่งที่คุณได้รับจากการทำงาน หากคุณต้องก
เมื่อการตั้งค่าสมบัติทรัพย์นี้ใด ๆ Welds หรือ Motor6Ds ที่เชื่อมต่อกับส่วนนี้จะมีค่าตร
WeldSeconds จะถูกปิดใช้งานชั่วคราวและเปิดให้ใช้อีกครั้งในระหว่างการเคลื่อนที่
ตัวอย่างโค้ด
This code sample rotates a part continually on the Y axis.
local part = script.Parent
local INCREMENT = 360 / 20
-- Rotate the part continually
while true do
for degrees = 0, 360, INCREMENT do
-- Set only the Y axis rotation
part.Rotation = Vector3.new(0, degrees, 0)
-- A better way to do this would be setting CFrame
--part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(degrees), 0)
task.wait()
end
end
PivotOffset
สมบัตินี้ระบุค่าเฉลี่ยของส่วนหมุนจาก Datatype.CFrame ของมันซึ่งคือ part:GetPivot() เป็นเดียวกับ part.CFrame * part.PivotOffset part:GetPivot()
นี่เป็นวิธีที่สะดวกในการตั้งโจมตีไปยังสถานที่ในพื้นที่ ล็อค แต่การตั้งโจมตีของบางส่วนในพื้นที่ โลก สามารถทำได้ด้วยวิธีต่อไปนี้:
local part = workspace.BluePartlocal desiredPivotCFrameInWorldSpace = CFrame.new(0, 10, 0)part.PivotOffset = part.CFrame:ToObjectSpace(desiredPivotCFrameInWorldSpace)
ตัวอย่างโค้ด
This code sample shows a custom function for resetting the pivot of a model back to the center of that model's bounding box.
local function resetPivot(model)
local boundsCFrame = model:GetBoundingBox()
if model.PrimaryPart then
model.PrimaryPart.PivotOffset = model.PrimaryPart.CFrame:ToObjectSpace(boundsCFrame)
else
model.WorldPivot = boundsCFrame
end
end
resetPivot(script.Parent)
This code sample creates a clock at the origin with a minute, second, and hour hand, and makes it tick, displaying the local time.
local function createHand(length, width, yOffset)
local part = Instance.new("Part")
part.Size = Vector3.new(width, 0.1, length)
part.Material = Enum.Material.Neon
part.PivotOffset = CFrame.new(0, -(yOffset + 0.1), length / 2)
part.Anchored = true
part.Parent = workspace
return part
end
local function positionHand(hand, fraction)
hand:PivotTo(CFrame.fromEulerAnglesXYZ(0, -fraction * 2 * math.pi, 0))
end
-- Create dial
for i = 0, 11 do
local dialPart = Instance.new("Part")
dialPart.Size = Vector3.new(0.2, 0.2, 1)
dialPart.TopSurface = Enum.SurfaceType.Smooth
if i == 0 then
dialPart.Size = Vector3.new(0.2, 0.2, 2)
dialPart.Color = Color3.new(1, 0, 0)
end
dialPart.PivotOffset = CFrame.new(0, -0.1, 10.5)
dialPart.Anchored = true
dialPart:PivotTo(CFrame.fromEulerAnglesXYZ(0, (i / 12) * 2 * math.pi, 0))
dialPart.Parent = workspace
end
-- Create hands
local hourHand = createHand(7, 1, 0)
local minuteHand = createHand(10, 0.6, 0.1)
local secondHand = createHand(11, 0.2, 0.2)
-- Run clock
while true do
local components = os.date("*t")
positionHand(hourHand, (components.hour + components.min / 60) / 12)
positionHand(minuteHand, (components.min + components.sec / 60) / 60)
positionHand(secondHand, components.sec / 60)
task.wait()
end
Position
คุณสมบัติตําแหน่งอธิบายตําแหน่งของ part โดยใช้ Vector3 นอกจากนี้ยังสะท้อนตําแหน่งของ BasePart.CFrame ของผู้อื่น
เมื่อการตั้งค่าสมบัติทรัพย์นี้ใด ๆ Welds หรือ Motor6Ds ที่เชื่อมต่อกับส่วนนี้จะมีค่าตร
WeldSeconds จะถูกปิดใช้งานชั่วคราวและเปิดให้ใช้อีกครั้งในระหว่างการเคลื่อนที่
ReceiveAge
นี่คือเวลาในวินาทีตั้งแต่วิทยาศาสตร์ของชิ้นส่วนได้รับการปรับปรุงครั้งสุดท้ายในเครื่องคอมพิวเตอร์ท้องถิ่น (หรือเซิร์ฟเวอร์) การกลับมา 0 เมื่อชิ้นส่วนไม่มีฟิสิกส์ (ติดอันเชียร์)
Reflectance
คุณสมบัติ Reflectance กำหนดว่าเท่าไหร่ part สะท้อนกล่องท้องฟ้า มีค่า 0 หมายถึงว่าส่วนไม่สะท้องเลย และมีค่า 1 หมายถึงว่าส่วนนั้นสะท้องเต็มที่
ความสะท้อนไม่ได้รับผลกระทบโดย BasePart.Transparency ยกเว้นว่าจะเป็นสีโปร่งใสอย่างสมบูรณ์หรือไม่ ในกรณีนี้ความสะท้อนจะไม่เรนเดอร์เลย ความสะท้อนอาจหรืออาจไม่ได้รับการ
ตัวอย่างโค้ด
This code sample causes a part to blink its Reflectance and a PointLight every time it is touched. It uses a pattern that prevents multiple concurrent function calls from fighting with each other.
local part = script.Parent
local pointLight = Instance.new("PointLight")
pointLight.Brightness = 0
pointLight.Range = 12
pointLight.Parent = part
local touchNo = 0
local function blink()
-- Advance touchNo to tell other blink() calls to stop early
touchNo = touchNo + 1
-- Save touchNo locally so we can tell when it changes globally
local myTouchNo = touchNo
for i = 1, 0, -0.1 do
-- Stop early if another blink started
if touchNo ~= myTouchNo then
break
end
-- Update the blink animation
part.Reflectance = i
pointLight.Brightness = i * 2
task.wait(0.05)
end
end
part.Touched:Connect(blink)
ResizeIncrement
สมบัติคุณลักษณะของ ResizeIncrement คือสมบัติคุณลักษณะที่อ่านเท่านั้นที่อธิบายการเปลี่ยนแปลงขนาดที่เล็กที่สุดที่อนุญ
ตัวอย่างโค้ด
This code sample creates a Handles object and shows how to set the Faces property of the object. It also references ResizeableFaces of a part. Try placing this script in multiple kinds of parts to see how ResizeableFaces varies.
-- Put this Script in several kinds of BasePart, like
-- Part, TrussPart, WedgePart, CornerWedgePart, etc.
local part = script.Parent
-- Create a handles object for this part
local handles = Instance.new("Handles")
handles.Adornee = part
handles.Parent = part
-- Manually specify the faces applicable for this handle
handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left)
-- Alternatively, use the faces on which the part can be resized.
-- If part is a TrussPart with only two Size dimensions
-- of length 2, then ResizeableFaces will only have two
-- enabled faces. For other parts, all faces will be enabled.
handles.Faces = part.ResizeableFaces
ResizeableFaces
สมบัติของเนื้อหาที่มีขนาดใหญ่ โดยทั่วไปแล้วจะเป็นรูปสี่เหลี่ยมผืนผ้าที่มีขนา
ตัวอย่างโค้ด
This code sample creates a Handles object and shows how to set the Faces property of the object. It also references ResizeableFaces of a part. Try placing this script in multiple kinds of parts to see how ResizeableFaces varies.
-- Put this Script in several kinds of BasePart, like
-- Part, TrussPart, WedgePart, CornerWedgePart, etc.
local part = script.Parent
-- Create a handles object for this part
local handles = Instance.new("Handles")
handles.Adornee = part
handles.Parent = part
-- Manually specify the faces applicable for this handle
handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left)
-- Alternatively, use the faces on which the part can be resized.
-- If part is a TrussPart with only two Size dimensions
-- of length 2, then ResizeableFaces will only have two
-- enabled faces. For other parts, all faces will be enabled.
handles.Faces = part.ResizeableFaces
RightSurface
ตัวองศาที่เหมาะสมจะกำหนดประเภทของพื้นผิวที่ใช้สำหรับทิศทาง +X ของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนวางอยู่ต่อกันสองด้านอาจสร้างช่องร่วมระหว่างพวกเขา หากกำหนดเป็นมอ
ส่วนใหญ่ของ SurfaceTypes จะเรนเดอร์เนื้อผิวบนหน้าผิวหาก BasePart.Material ติดตั้งไว้ที่ Plastic บาง SurfaceTypes รวมทั้ง Hinge, Motor และ SteppingMotor จะเรนเดอร์ออร์นาเมนต์ 3D แทน
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
RootPriority
ค่านี้เป็นตัวเลขระหว่าง -127 และ 127 ที่มีความสามารถเหนือกฎของรูปแบบรวมทั้งหมดสำหรับการเรียงลำดับส่วนราก เมื่อพิ
คุณสามารถใช้สมบัตินี้เพื่อควบคุมส่วนไหนของการประกอบการที่เป็นส่วนรากและให้รากเสถียรหากขนาดเปลี่ยนแปลง
ดูเพิ่มเติมที่ การประกอบการกับกัน บทความที่อธิบายว่าอะไหล่รากเป็นอย่างไรและจะใช้งานได้อย่างไร
Rotation
การหมุนของส่วนในองศาสำหรับสามแกน
เมื่อการตั้งค่าสมบัติทรัพย์นี้ใด ๆ Welds หรือ Motor6Ds ที่เชื่อมต่อกับส่วนนี้จะมีค่าตร
WeldSeconds จะถูกปิดใช้งานชั่วคราวและเปิดให้ใช้อีกครั้งในระหว่างการเคลื่อนที่
Size
สมบัติของ Size จะกำหนดขนาด ทางสายตา ของมันโดยใช้ค่า ExtentsSize
ขนาดของชิ้นส่วนกำหนดความวิตกรรมที่ได้รับโดย BasePart:GetMass() ส่วนของชิ้นส่วน Size ใช้โดยวัตถุที่หลากหลาย:
- ParticleEmitter เพื่อระบุพื้นที่ที่อนุภาคเกิดขึ้น
- BlockMesh เพื่อระบุส่วนหนึ่งของเลนส์สี่เหลี่ยมผืนผ้าที่เรนเดอร์
- SpecialMesh สำหรับบาง MeshTypes เพื่อกำหนดขนาดของเมชที่เรนเดอร์
- SurfaceLight เพื่อกำหนดพื้นที่ที่จะประกาย
ตัวอย่างโค้ด
This code sample constructs a pyramid by stacking parts that get progressively smaller. It also colors the parts so they blend between a start color and end color.
local TOWER_BASE_SIZE = 30
local position = Vector3.new(50, 50, 50)
local hue = math.random()
local color0 = Color3.fromHSV(hue, 1, 1)
local color1 = Color3.fromHSV((hue + 0.35) % 1, 1, 1)
local model = Instance.new("Model")
model.Name = "Tower"
for i = TOWER_BASE_SIZE, 1, -2 do
local part = Instance.new("Part")
part.Size = Vector3.new(i, 2, i)
part.Position = position
part.Anchored = true
part.Parent = model
-- Tween from color0 and color1
local perc = i / TOWER_BASE_SIZE
part.Color = Color3.new(
color0.R * perc + color1.R * (1 - perc),
color0.G * perc + color1.G * (1 - perc),
color0.B * perc + color1.B * (1 - perc)
)
position = position + Vector3.new(0, part.Size.Y, 0)
end
model.Parent = workspace
TopSurface
คุณสมบัติ TopSurface กำหนดประเภทของพื้นผิวที่ใช้สำหรับ +Y ทิศทางของชิ้นส่วน เมื่อสองด้านของชิ้นส่วนวางอยู่ต่อหน้ากัน พวกเขาอาจสร้างการรวมกันระหว่างพวกเขา หากกำหนดไว้ที่มอ
ส่วนใหญ่ของ SurfaceTypes จะเรนเดอร์เนื้อผิวบนหน้าผิวหาก BasePart.Material ติดตั้งไว้ที่ Plastic บาง SurfaceTypes - Hinge, Motor และ SteppingMotor - จะเรนเดอร์ออร์แนมเมนต์ 3D แทน หากโ
ตัวอย่างโค้ด
This code sample shows what each SurfaceType looks like on a part. In addition, it creates a BillboardGui label on the part with a TextLabel that reflects the name of the current SurfaceType.
local demoPart = script.Parent
-- Create a billboard gui to display what the current surface type is
local billboard = Instance.new("BillboardGui")
billboard.AlwaysOnTop = true
billboard.Size = UDim2.new(0, 200, 0, 50)
billboard.Adornee = demoPart
local textLabel = Instance.new("TextLabel")
textLabel.Size = UDim2.new(0, 200, 0, 50)
textLabel.BackgroundTransparency = 1
textLabel.TextStrokeTransparency = 0
textLabel.TextColor3 = Color3.new(1, 1, 1) -- White
textLabel.Parent = billboard
billboard.Parent = demoPart
local function setAllSurfaces(part, surfaceType)
part.TopSurface = surfaceType
part.BottomSurface = surfaceType
part.LeftSurface = surfaceType
part.RightSurface = surfaceType
part.FrontSurface = surfaceType
part.BackSurface = surfaceType
end
while true do
-- Iterate through the different SurfaceTypes
for _, enum in pairs(Enum.SurfaceType:GetEnumItems()) do
textLabel.Text = enum.Name
setAllSurfaces(demoPart, enum)
task.wait(1)
end
end
Transparency
สมบัติคุณสมบัติความโปร่งใสควบคุมความมองเห็นของชิ้นส่วนบนเครื่องชี้วัด 0 ถึง 1 โดยที่ 0 เป็นสมบัติความโปร่งใสสมบูรณ์ (มองไม่เห็น) และมีค่า 1 เป็นสมบัติความโปร่งใสทั้งหมด (ไม่เรนเดอร์)
BasePart.Reflectance สามารถลดความโปร่งใสทั้งหมดของอิฐหากตั้งค่าใกล้เคียงกับ 1
ในขณะที่ชิ้นส่วนโปร่งใสมากไม่ได้เรนเดอร์เลย การดำเนินการการมีชิ้นส่วนโปร่งใสมากมายอาจทำให้เกมช้าลง
เมื่อชิ้นส่วนโปร่งใสมีความสัมพันธ์กัน คำสั่งเรนเดอร์อาจทำงานได้อย่างไม่คาดคิด - พยายามให้ชิ้นส่วนโปร่งใสเหล่านี้อยู่ในระหว่างการเรนเดอร์เพื่อหลีกเลี่ยงสิ่งนี้
Class.BasePart.LocalTransparency เป็นตัวคูณของความโปร่งใสที่มองเห็นได้เฉพาะลูกค้าเท่านั้น
ตัวอย่างโค้ด
This code sample shows how a part can fade away when touched by a Humanoid then reappear a moment after to create a passable door.
-- Paste into a Script inside a tall part
local part = script.Parent
local OPEN_TIME = 1
-- Can the door be opened at the moment?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("Black")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("Bright blue")
end
local function onTouch(otherPart)
-- If the door was already open, do nothing
if debounce then
print("D")
return
end
-- Check if touched by a Humanoid
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("not human")
return
end
-- Perform the door opening sequence
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()
This code sample gives the local client X-ray vision using LocalTransparencyModifier. It allows the player to see through all parts in the Workspace, which are found using recursion.
local function makeXRayPart(part)
-- LocalTransparencyModifier will make parts see-through but only for the local
-- client, and it won't replicate to the server
part.LocalTransparencyModifier = 0.5
end
-- This function uses recursion to search for parts in the game
local function recurseForParts(object)
if object:IsA("BasePart") then
makeXRayPart(object)
end
-- Stop if this object has a Humanoid - we don't want to see-through players!
if object:FindFirstChildOfClass("Humanoid") then
return
end
-- Check the object's children for more parts
for _, child in pairs(object:GetChildren()) do
recurseForParts(child)
end
end
recurseForParts(workspace)
วิธีการ
AngularAccelerationToTorque
พารามิเตอร์
ส่งค่ากลับ
ApplyAngularImpulse
ใช้แรงโน้มถ่วงแบบเร่งขึ้นในทิศทางนี้สำหรับการประกอบของชิ้นส่วนนี้ ทำให้การประกอบหมุน
ความเร็วมุมที่เกิดขึ้นจากกระแทกขึ้นอยู่กับการประกอบของ mass ดังนั้นจึงจำเป็นต้องใช้แรงกระแทกที่มากขึ้นเพื่อย้ายกองกวดขนาดใหญ่ การกระแทกเป็นประโยชน์ส
หากชิ้นส่วนเป็นของเซิร์ฟเวอร์ หน้านี้จะต้องเรียกจาก
พารามิเตอร์
เป็นเวกเตอร์แรงที่จะถูกประยุกต์ให้กับการประกอบตัวอันเป็นขั้นเร่ง
ส่งค่ากลับ
ApplyImpulse
ฟังก์ชันนี้ใช้แรงโน้มถ่วงทันทีเพื่อการประกอบของชิ้นส่วนนี้
ความกระทำนี้ได้รับการประยุกต์ใช้ที่ center of mass ดังนั้นการเคลื่อนที่ที่เกิดขึ้นจะเป็นเพียงแนวเส้น
ความเร็วที่เกิดขึ้นจากการเร่งขึ้นอยู่กับ mass ของการประกอบ ดังนั้นจึงจำเป็นต้องใช้แรงกดเพิ่มขึ้นเพื่อย้ายการประกอบที่มีขนาดใหญ่ขึ้น การเร่งมีประโย
หากชิ้นส่วนเป็นของเซิร์ฟเวอร์ หน้านี้จะต้องเรียกจาก
พารามิเตอร์
เป็นเวกเตอร์แรงที่จะถูกประยุกต์ให้กับการประกอบตัวอันเป็นขั้นเร่ง
ส่งค่ากลับ
ApplyImpulseAtPosition
ฟังก์ชันนี้ใช้แรงกระตุกในทันทีเพื่อให้ประกอบของส่วนนี้ในตำแหน่งที่กำหนดในพื้นที่โลก
หากตําแหน่งไม่ได้อยู่ที่ศูนย์กลางของการประกอบการ center of mass จะทําให้เกิดการเคลื่อนที่ทางกายภาพและการหมุน
ความเร็วที่เกิดขึ้นจากการกระตุ้นขึ้นอยู่กับการประกอบการ mass ของการประกอบการ ดังนั้นจึงจำเป็นต้องใช้การกระตุ้นมากขึ้นเพื่อย้ายการประกอบการที่มีขนาดให
หากชิ้นส่วนเป็นของเซิร์ฟเวอร์ หน้านี้จะต้องเรียกจาก
พารามิเตอร์
เป็นเวกเตอร์แรงที่จะถูกประยุกต์ให้กับการประกอบตัวอันเป็นขั้นเร่ง
ตําแหน่งในพื้นที่โลกเพื่อใช้แรงกระตุก
ส่งค่ากลับ
CanCollideWith
กลับว่าชิ้นส่วนสามารถชนกันได้หรือไม่ ฟังก์ชันนี้จะพิจารณากลุ่มการชนของสองชิ้นส่วน
พารามิเตอร์
กำลังตรวจสอบส่วนที่กำหนดเพื่อความสามารถในการชน
ส่งค่ากลับ
ว่าชิ้นส่วนสามารถชนกันได้หรือไม่
CanSetNetworkOwnership
คุณสมบัติ CanSetNetworkOwnership ตรวจสอบว่าคุณสามารถตั้งค่าเครือข่ายของบางส่วนได้หรือไม่
ค่าการกลับของฟังก์ชันตรวจสอบว่าคุณสามารถเรียก BasePart:SetNetworkOwner() หรือ BasePart:SetNetworkOwnershipAuto() โดยไม่เจอข้อผิดพลาด มันจะกลับมาเป็นค่า true หากคุณสามารถปรับแก้
ส่งค่ากลับ
ว่าคุณสามารถปรับแก้หรืออ่านความเป็นเจ้าของเครือข่ายและเหตุผล
ตัวอย่างโค้ด
This example checks whether or not the network ownership of the first BasePart named Part in the Workspace can be set.
local part = workspace:FindFirstChild("Part")
if part and part:IsA("BasePart") then
local canSet, errorReason = part:CanSetNetworkOwnership()
if canSet then
print(part:GetFullName() .. "'s Network Ownership can be changed!")
else
warn("Cannot change the Network Ownership of " .. part:GetFullName() .. " because: " .. errorReason)
end
end
GetConnectedParts
กลับตารางของชิ้นส่วนที่เชื่อมต่อกับวัตถุโดยประเภทของข้อต่อที่แข็งแกร่ง
หาก recursive เป็นจริง ฟังก์ชันนี้จะส่งคืนทุกส่วนในการประกอบที่เชื่อมติดกับ BasePart อย่างแน่นหนา
ข้อต่อที่แข็งแกร่ง
เมื่อสองส่วนเชื่อมต่อกัน (Part0 → Part1) สองส่วนจะเป็น แข็ง หากวิทยาศาสตร์ของ Part1 ถูกล็อกไว้อย่างสมบูรณ์โดย 1> Part01> นี่ใช้ได้เฉพาะประเภทของ
พารามิเตอร์
ส่งค่ากลับ
GetJoints
กลับส่วนของร่วมหรือข้อจํากัดที่เชื่อมต่อกับส่วนนี้
ส่งค่ากลับ
รายการของคู่หรือข้อจํากัดทั้งหมดที่เชื่อมต่อกับ Part
GetMass
รับ Mass คืนค่าของสมบัติสินค้า Mass
คุณสมบัตินี้มีอยู่แล้วในสมบัติมวล
ส่งค่ากลับ
พลังงานของชิ้นส่วน
ตัวอย่างโค้ด
This example creates a new part, myPart, in the game's Workspace, with dimensions 4x6x4 studs. The part is also anchored.
Then, myMass is set to equal the mass of the new part. The mass of the part is printed at the end of the print statement:
My part's mass is ...
local myPart = Instance.new("Part")
myPart.Size = Vector3.new(4, 6, 4)
myPart.Anchored = true
myPart.Parent = workspace
local myMass = myPart:GetMass()
print("My part's mass is " .. myMass)
GetNetworkOwner
กลับผู้เล่นปัจจุบันที่เป็นเจ้าของเครือข่ายของส่วนนี้ หรือ zero ในกรณีของเซิร์ฟเวอร์
ส่งค่ากลับ
ผู้เล่นปัจจุบันที่เป็นเจ้าของเครือข่ายของส่วนนี้หรือ zero ในกรณีของเซิร์ฟเวอร์
GetNetworkOwnershipAuto
กลับ true หากเครื่องยนต์เกมตัดสินผู้สมัครเครือข่ายสำหรับส่วนนี้โดยอัตโนมัติ
ส่งค่ากลับ
ว่าเครื่องมือเกมจะตัดสินผู้สร้างเครือข่ายสำหรับส่วนนี้โดยอัตโนมัติหรือไม่
GetNoCollisionConstraints
ส่งค่ากลับ
GetRootPart
กลับส่วนประกอบพื้นฐานของการประกอบ เมื่อย้ายการประกอบของชิ้นส่วนโดยใช้ CFrame ให้สำคัญที่จะย้ายส่วนประกอบนี้ (ซึ่งจะย้ายชิ้นส่วนอื่นที่เกี่ยวข้องกับมันตามลำดั
ฟังก์ชันนี้เก่ากว่าสมบัติของ AssemblyRootPart สมบัติ มันยังคงรองรับการใช้งานในอดีต แต่คุณควรใช้ AssemblyRootPart โดยตรง
ส่งค่ากลับ
ส่วนประกอบพื้นฐานของการประกอบ (คอลเลกชันของชิ้นส่วนที่เชื่อมต่อกัน)
GetTouchingParts
กลับตารางของผลลัพธ์ทั้งหมดที่เกี่ยวข้องกับส่วนนี้ หากส่
ส่งค่ากลับ
ตารางของผู้ชินกับและสามารถชนกับส่วนนี้
GetVelocityAtPosition
กลับค่าความเร็วเส้นที่เป็นลิнейของการประกอบของชิ้นส่วนในตำแหน่งที่ให้ไว้เมื่อเป็นส่วนหนึ่งของการประกอบ สามารถใช้เพื่อระบุความเร็วเส้นที่เป็นลิнейของชิ้นส่วนในการประกอบอื่นนอก
พารามิเตอร์
ส่งค่ากลับ
IsGrounded
กลับ true หากวัตถุเชื่อมต่อกับส่วนที่จะรองรับมันในที่ (เช่น Anchored ส่วน) หรือไม่ ก็จะกลับ false ตรงกัน ในการประกอบที่มีส่วนที่ว่างอยู่ ทุกส่วนอ
ส่งค่ากลับ
ว่าตัวอุปกรณ์เชื่อมต่อกับส่วนที่จะรักษาตำแหน่งไว้หรือไม่
Resize
เปลี่ยนขนาดของวัตถุเหมือนการใช้เครื่องมือขยายขนาดใน Studio
พารามิเตอร์
ด้านข้างที่จะปรับขนาด
เท่าไหร่จะเติบโต/หดบนด้านที่กำหนด
ส่งค่ากลับ
ว่าอะไหล่จะปรับขนาดหรือไม่
SetNetworkOwner
ตั้งผู้เล่นที่ให้เป็นเจ้าของเครือข่ายสำหรับส่วนนี้และส่วนที่เชื่อมต่อทั้งหมด เมื่อ playerInstance เป็น zero จะเป็นเจ้าของเซิร์ฟเวอร์แทนที่จะเป็นผู้เล่น
พารามิเตอร์
ผู้เล่นได้รับการเป็นเจ้าของเครือข่ายส่วน
ส่งค่ากลับ
SetNetworkOwnershipAuto
ให้เครื่องมือเกมตัดสินใจได้อย่างไดนามิกว่าใครจะดูแลฟิสิกส์ของชิ้นส่วน (หนึ่งในลูกค้าหรือเซิร์ฟเวอร์)
ส่งค่ากลับ
TorqueToAngularAcceleration
พารามิเตอร์
ส่งค่ากลับ
IntersectAsync
สร้าง IntersectOperation ใหม่จากเหลี่ยมของชิ้นส่วนและอื่น ๆ ในแถวที่ระบุ เฉพาะ Parts เท่า
ลักษณะต่อไปนี้จากส่วนที่เรียกจะถูกประยุกต์ให้กับผลลัพธ์ IntersectOperation :
- Class.BasePart.Color|Color , Material , MaterialVariant , 0> Class.BasePart.Reflectance|Reflectance0> , Color3>
- Class.BasePart.Anchored|Anchored , Density , Elasticity , 0> Class.BasePart.ElasticityWeight|Elasticity0> , 3> Class.BasePart.Friction
ในภาพประกอบต่อไปนี้, IntersectAsync() เรียกใช้บล็อกสีม่วงโดยใช้ตารางที่มีบล็อกสีน้ำเงิน ผลลัพธ์ IntersectOperation จะแก้ไขเป็นรูปร่างของเรื่องโค้งเรือของทั้งส

<figcaption>ชิ้นส่วนที่แยกออกจากกัน</figcaption>

<figcaption>ผล <code>Class.IntersectOperation</code></figcaption>
โน้ต
- ส่วนที่เป็นต้นฉบับจะเหลือไว้หลังจากการแสดงผลที่ประสบความสำเร็จ ในกรณีส่วนใหญ่คุณควร Destroy() ทั้งหมดของส่วนที่เป็นต้นฉบับและพ่อของส่วนที่เป็นต้นฉ
- โดยปกติสีหน้าของผลลัพธ์จะถูกยืมจากสมบัติของ Color ของบรรทัดฉบับแรก เพื่อเปลี่ยนสีทั้งหมดให้เป็นสีเฉพาะ ตั้งค่าสมบัติของ Class.PartOperation.UsePartColor|UsePartColor
- หากการเชื่อมต่อกันจะผลิตให้เป็นส่วนที่มีมากกว่า 20,000 เหลี่ยมมุม มันจะถูกเรียบเรียงเป็น 20,000 เหลี่ยมมุม
พารามิเตอร์
วัตถุที่มีส่วนร่วมในการเข้าสู่สถานที่โดยรวม
ค่า Enum.CollisionFidelity สำหรับผลลัพธ์ IntersectOperation
ค่า Enum.RenderFidelity ที่ได้รับจากผลลัพธ์ PartOperation
ส่งค่ากลับ
ผลลัพธ์ IntersectOperation ด้วยชื่อเรื่อง Intersect โดยปกติ
SubtractAsync
สร้าง UnionOperation ใหม่จากส่วน โดยลบภูเขาที่โดดเด่นโดยผู้ชนะในแผนที่ที่ให้ไว้ เฉพาะ Parts
หมายเหตุว่าค่าตัวผสมที่ผลลัพธ์จะไม่สามารถว่างเปล่าเนื่องจากการลบ
ในภาพประกอบต่อไปนี้, SubtractAsync() เรียกใช้ในสีฟ้าโดยใช้ตารางที่มีบล็อกสีม่วง ผลลัพธ์ UnionOperation จะแก้ไขเป็นรูปร่างที่ปล่อยให้รูปร่างของบล็อกนั

<figcaption>ชิ้นส่วนที่แยกออกจากกัน</figcaption>

<figcaption>ผลลัพธ์ <code>Class.UnionOperation</code></figcaption>
พารามิเตอร์
วัตถุที่มีส่วนร่วมในการลบ
ค่า Enum.CollisionFidelity สำหรับผลลัพธ์ UnionOperation
ค่า Enum.RenderFidelity ที่ได้รับจากผลลัพธ์ PartOperation
ส่งค่ากลับ
ผล UnionOperation ด้วยชื่อเริ่มต้น สหภาพ
ตัวอย่างโค้ด
This example demonstrates how to subtract part(s) from another BasePart to form a negated UnionOperation.
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Perform subtract operation
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newSubtract then
newSubtract.Position = mainPart.Position
newSubtract.Parent = Workspace
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
UnionAsync
สร้าง UnionOperation ใหม่จากส่วน รวมทั้งภาพที่เป็นภาพของส่วนในแผงที่ให้ เฉพาะ Parts เท่าน
ลักษณะต่อไปนี้จากส่วนที่เรียกจะถูกประยุกต์ให้กับผลลัพธ์ UnionOperation :
- Class.BasePart.Color|Color , Material , MaterialVariant , 0> Class.BasePart.Reflectance|Reflectance0> , Color3>
- Class.BasePart.Anchored|Anchored , Density , Elasticity , 0> Class.BasePart.ElasticityWeight|Elasticity0> , 3> Class.BasePart.Friction
ในภาพประกอบต่อไปนี้, UnionAsync() เรียกใช้บล็อกสีน้ำเงินโดยใช้ตารางที่มีทรงกระบอกสีม่วง ผลลัพธ์ UnionOperation จะแปลงเป็นรูปร่างของการผสานรวมของทั้งสองส่วน

<figcaption>ชิ้นส่วนที่แยกออกจากกัน</figcaption>

<figcaption>ผลลัพธ์ <code>Class.UnionOperation</code></figcaption>
โน้ต
- ส่วนที่เป็นต้นฉบับจะเหลืออยู่หลังจากการผสานที่ประสบความสำเร็จ ในกรณีส่วนใหญ่คุณควร Destroy() ทั้งหมดของส่วนที่เป็นต้นฉบับและพ่อของผลกลับมาที่นี่เดีย
- โดยปกติ, ความสัมพันธ์ที่เกิดขึ้นจะเคารพค่า Color ของแต่ละส่วนของมัน เพื่อเปลี่ยนทั้งหมดของความสัมพันธ์เป็นสีเฉพาะ, กำหนดค่า Class.PartOperation.UsePartColor|UsePart
- หากคำนวณค่าความเป็นสมการของสหภาพจะผลให้เป็นส่วนที่มีมากกว่า 20,000 เหลี่ยมจักร จะถูกเรียบเรียงเป็นเหลี่ยมจักร 20,000 เหลี่ยมจักร
พารามิเตอร์
วัตถุที่มีส่วนร่วมในสหภาพกับส่วนที่เรียก
ค่า Enum.CollisionFidelity สำหรับผลลัพธ์ UnionOperation
ค่า Enum.RenderFidelity ที่ได้รับจากผลลัพธ์ PartOperation
ส่งค่ากลับ
ผล UnionOperation ด้วยชื่อเริ่มต้น สหภาพ
ตัวอย่างโค้ด
This example demonstrates how to combine the geometry of one BasePart with the geometry of other part(s) to form a UnionOperation.
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- Perform union operation
local success, newUnion = pcall(function()
return mainPart:UnionAsync(otherParts)
end)
-- If operation succeeds, position it at the same location and parent it to the workspace
if success and newUnion then
newUnion.Position = mainPart.Position
newUnion.Parent = Workspace
end
-- Destroy original parts which remain intact after operation
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end
อีเวนต์
TouchEnded
เกิดเมื่อชิ้นส่วนหยุดสัมผัสกับอีกชิ้นส่วนภายใต้เงื่อนไขที่คล้ายกับ BasePart.Touched
เหตุการณ์นี้ทำงานร่วมกับ Workspace.TouchesUseCollisionGroups เพื่อระบุว่า กลุ่มความตรงกัน ได้รับการยอมรับสำหรับการตรวจจับหรือไม่
พารามิเตอร์
ตัวอย่างโค้ด
This code sample creates a BillboardGui on a part that displays the number of parts presently touching it.
local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
Touched
เหตุการณ์ แตะ เกิดขึ้นเมื่อชิ้นส่วนมาในติดต่อกับอีกชิ้นส่วน อินสแตนซ์หาก ชิ้นส่วน A ชนกับ
เหตุการณ์นี้เกิดขึ้นเฉพาะในผลมาจากการเคลื่อนไหวทางกายภาพดังนั้นจึงจะไม่เกิดได้หาก CFrame สมบัติร่วมกันถูกเปลี่ยนให้เป็
เหตุการณ์นี้ทำงานร่วมกับ Workspace.TouchesUseCollisionGroups เพื่อระบุว่า กลุ่มความตรงกัน ได้รับการยอมรับสำหรับการตรวจจับหรือไม่
พารามิเตอร์
ส่วนอื่นที่มีการติดต่อกับส่วนที่ให้
ตัวอย่างโค้ด
This code sample creates a BillboardGui on a part that displays the number of parts presently touching it.
local part = script.Parent
local billboardGui = Instance.new("BillboardGui")
billboardGui.Size = UDim2.new(0, 200, 0, 50)
billboardGui.Adornee = part
billboardGui.AlwaysOnTop = true
billboardGui.Parent = part
local tl = Instance.new("TextLabel")
tl.Size = UDim2.new(1, 0, 1, 0)
tl.BackgroundTransparency = 1
tl.Parent = billboardGui
local numTouchingParts = 0
local function onTouch(otherPart)
print("Touch started: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("Touch ended: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
This code sample demonstrates how to connect the BasePart.Touched event of multiple parts in a Model to one function.
local model = script.Parent
local function onTouched(otherPart)
-- Ignore instances of the model coming in contact with itself
if otherPart:IsDescendantOf(model) then return end
print(model.Name .. " collided with " .. otherPart.Name)
end
for _, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onTouched)
end
end