概要
屬性
決定零件是否因物理學而無法移動。
零件裝配的角速度。
零件在世界空間的質量中心。
零件裝配的線速度。
零件裝配的總重量。
指向裝配的根部分。
決定零件後面的表面類型 (+Z方向)。
決定零件底面的表面類型(-Y方向)。
決定零件的顏色。
決定世界中 BasePart 的位置和方向。
決定零件是否可能與其他零件碰撞。
決定零件在空間查詢操作期間是否被考慮。
決定是否 Touched 和 TouchEnded 事件在零件上發射。
決定零件是否投射陰影。
描述零件的重心位置在哪裡。
描述零件衝突群組的名稱。
決定零件的顏色。
指示零件目前的物理特性。
決定零件的多個物理特性。
用於啟用或禁用零件和裝配的空氣動力。
物理引擎所看到的 BasePart 實際尺寸。
決定零件前面的表面類型(-Z方向)。
決定零件左面的表面類型(-X方向)。
決定只對本地客戶可見的乘數 BasePart.Transparency 。
決定零件是否可在 Studio 中選擇。
描述零件的質量、密度和體積的產品。
決定零件是否會對其剛性身體的總質量或慣性有貢獻。
決定零件的紋理和預設物理特性。
MaterialVariant 的名稱。
描述世界中零件的旋轉。
指定零件的軸偏移來自其 CFrame 。
描述零件在世界上的位置。
上次記錄物理更新的時間。
決定零件是否反映了天空盒。
描述縮放方法可允許的最小尺寸變更。
描述可以縮放零件的面。
決定零件右面的表面類型 (+X 方向)。
決定組裝根部分的主要規則。
零件在三軸上的旋轉度。
決定零件的尺寸(長度、寬度、高度)。
決定零件頂部面的表面類型 (+Y 方向)。
決定零件能被看到多少(與零件隱形度相反)。
方法
對裝配應用角度脈沖。
在裝配的 center of mass 應用脈沖到裝配。
在指定位置應用脈沖到裝配。
返回零件是否可以相互碰撞。
檢查您是否可以設置零件的網絡所有權。
返回包含任何種類剛性聯組合的對象與零件的表。
返回連接到此零件的所有關節或限制。
返回 Mass 屬性的值。
返回這部分網絡所有者的當前玩家,或在伺服器的情況下返回 nil。
如果遊戲引擎自動決定此部分的網絡所有者,返回真值。
返回零件組合的基本零件。
返回包含這個部分交叉的所有 BasePart.CanCollide 真實零件的表。
返回零件在指定位置相對於此零件的線速度。
如果對象連接到會將其保持在位置的零件(例如 Anchored 零件),則返回真值;否則返回假值。
以相同於使用 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 ,加上給定數陣列中零件所佔的幾何圖形。
獲得 PVInstance 的軸心。
將 以及所有其子孫 轉換為指定的 位置,使旋轉點現在位於指定的 位置。
活動
當零件停止接觸其他零件,因為物理移動的結果時,發生火災。
當零件在物理移動的結果下觸碰另一零件時發生火災。
屬性
Anchored
錨定 屬性決定零件是否會被物理學移除。啟用時,零件將永遠不會因重力、其他零件碰撞、疊加其他零件或任何其他與物理相關的原因而改變位置。因結果,兩個被錨定的零件永遠不會對彼此發射 BasePart.Touched 事件。
錨定的零件仍然可以通過修改其 CFrame 或 Position 來移動,仍然可能具有非零 AssemblyLinearVelocity 和 AssemblyAngularVelocity 。
最後,如果未錨定的零件與錨定的零件通過像 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 來更改。
所有共享相同裝配根部分的零件都在同一裝配中。
有關根部件的更多資訊,請參閱裝配。
AudioCanCollide
BackSurface
回面屬性決定了零件的 +Z 方向使用的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.BackSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型 - 鉸、馬達和步進馬達 - 會渲染 3D 裝飾。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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
底部表面屬性決定了零件的 -Y 方向使用的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.BottomSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型 - 鉸、馬達和步進馬達 - 會渲染 3D 裝飾。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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
BrickColor 屬性決定零件的顏色。如果零件有 BasePart.Material,這也會決定在渲染材料紋理時使用的顏色。若要更多控制顏色,可以使用 BasePart.Color 屬性 (它是此屬性的 Color3 變體)。如果設定顏色,此屬性將使用最接近的磚色。
零件的其他視覺特性由 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 的位置和方向。它作為幾何上的任意參考位置,但 ExtentsCFrame 代表其物理中心的實際 CFrame 。
當在零件上設置 CFrame 時,其他加入的零件也會相對於零件移動,但建議您使用 PVInstance:PivotTo() 來移動整個模型,例如當傳送玩家角色時。
與設置 BasePart.Position 不同,設置 BasePart.CFrame 將永遠將零件移動到指定的 CFrame;換言之: 沒有重疊檢查 ,物理解決器將嘗試解決任何重疊,除非兩個零件都是 Anchored 。
若要跟蹤零件的位置 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 或 Raycast 。CanCollide在禁用CanQuery時也必須被禁用。這些功能永遠不會包含具有 CanQuery 和 CanCollide 為 false 的零件。
超過此屬性,還可以使用 OverlapParams 或 RaycastParams 對象來排除屬於給定列表的零件的子零件,當呼叫空間查詢函數時。
CanTouch
此屬性決定是否 Touched 和 TouchEnded 事件在零件上發生。如果 , 其他接觸部分也必須設為 以啟動觸摸事件。如果 false,觸發事件無法為零件設置,嘗試這樣做會發生錯誤。相同地,如果屬性在觸發觸碰事件後設為 false,事件將被切斷,並移除 TouchTransmitter。
請注意,此碰撞邏輯可以通過 碰撞群 屬性設置遵守 Workspace.TouchesUseCollisionGroups。如果 true , 非碰撞群中的零件將忽略 和 觸碰事件的碰撞,因此這個屬性變得無關。
性能
對於具有 CanTouch 和 CanCollide 設為 false 的零件,存在很小的性能提升,因為這些零件永遠不需要計算任何類型的零件對零件碰撞。然而,它們仍然可以被 Raycasts 和 OverlapParams 查詢擊中。
CastShadow
決定零件是否投射陰影。
請注意,此功能不是 不 設計用於性能提升。它只應在你想隱藏零件所投射的陰影的零件上停用。停用此特性對給定的零件可能會導致對該零件投射的陰影上的視覺缺陷。
CenterOfMass
CenterOfMass 屬性描述了零件中心質量的 本地 位置。如果這是單一零件裝配,這是從世界空間轉換為本地的 AssemblyCenterOfMass 。在簡單的 Parts 上,質量中心總是(0,0,0)。但它可能會因為 WedgePart 或 MeshPart 而變化。
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
顏色屬性決定零件的顏色。如果零件有 BasePart.Material,這也會決定在渲染材料紋理時使用的顏色。如果此屬性已設設定,BasePart.BrickColor將使用最接近的磚塊顏色與顏色3值。
零件的其他視覺特性由 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
自訂物理特性讓您自訂 Part 的各種物理特性,例如密度、摩擦和彈性。
啟用此屬性可讓您配置這些物理屬性。如果停用,這些物理屬性由零件的 BasePart.Material 決定。對於 Enum.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
FrontSurface
前表面屬性決定用於零件-Z方向的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.FrontSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型,包括鉸、馬達和步進馬達,會以 3D 裝飾代替。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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
左表面屬性決定了用於零件-X方向的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.LeftSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型,包括鉸、馬達和步進馬達,會以 3D 裝飾代替。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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))
<th>本地透明修改器</th><th>伺服器端透明度</th><th>客戶端透明度</th></tr></thead><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
鎖定屬性決定是否可以在 Roblox Studio 中通過單擊選擇 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)
Massless
如果此屬性啟用,BasePart將不會對組裝的總質量或慣性提供貢獻,只要它被焊接到另一個有質量的零件上。
如果零件是自己的根部分,根據 AssemblyRootPart ,這將被忽略為該零件,仍會為其裝配提供質量和慣性貢獻,就像普通零件一樣。沒有物質的零件永遠不應成為裝配根部分,除非所有其他零件也沒有物質。
這可能對於像選擇性配件在車輛上不想影響車輛操控或沒有質量的渲染網格焊接到簡單的碰撞網格有用。
也可以參閱裝配文章,該文件記錄了根部件是什麼以及如何使用它們。
Material
材料屬性允許建築師設置零件的紋理和預設物理屬性(如果 BasePart.CustomPhysicalProperties 未設置)。預設塑膠材料的紋理非常淺,平滑塑膠材料完全部 所有沒有紋理。一些材料紋理,例如鑽石板和花崗岩,有非常明顯的紋理。每種材料的紋理反射出不同的陽光,特別是鋁箔。
設定此屬性,然後啟用 BasePart.CustomPhysicalProperties 將使用材料的預設物理屬性。例個體、實例,DiamondPlate是非常稠密的材料,而木是非常輕的。零件的密度決定它是否會在地形水中漂浮。
玻璃材料會在中等圖形設定下變更渲染行為。它會應用一點反射(類似於 BasePart.Reflectance)和扭曲視角。效果特別明顯在球形零件上(設置 BasePart.Shape 為球)。玻璃後面的半透明物體和玻璃零件不可見。
範例程式碼
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
系統搜尋指定的物料變體名稱和 BasePart.Material 輸入的 MaterialVariant 實例。如果成功找到匹配的物質變體實個體、實例,它會使用此物質變體實例來替換預設物質。預設材料可以是內置材料或在 MaterialService 中指定的覆蓋材料變體。
Orientation
導向屬性描述零件在 X、Y 和 Z 軸上的旋轉度,使用 Vector3。旋轉在 Y → X → Z 順序中應用。這與正確的 埃爾勒角度 不同,而是 泰特-布萊恩角度 ,用於描述 偏航、俯仰和滾動 。值得注意的是,這個屬性與在不同順序中應用旋轉的 CFrame.Angles() 建造器有何不同 (Z → Y → X)。為了更好地控制零件的旋轉,建議設置 BasePart.CFrame 而不是。
當設置此屬性時,任何Welds或Motor6Ds連接到此部分的C0或C1屬性將被更新,以允許部分相對於任何其他部分移動。
焊接限制也會在移動工具動期間暫時停用並重新啟用。
範例程式碼
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
此屬性指定零件的旋轉點與其 CFrame 的偏移值,即 part:GetPivot() 與 part.CFrame * part.PivotOffset 相同。
將旋轉點設置為 本地 空間的位置很方便,但將零件的旋轉點設置為 世界 空間的位置可以按照以下方式進行:
local Workspace = game:GetService("Workspace")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連接到此部分的C0或C1屬性將被更新,以允許部分相對於任何其他部分移動。
焊接限制也會在移動工具動期間暫時停用並重新啟用。
Reflectance
反射率屬性決定了 part 反射多少天空盒。值 0 表示零件不反射任全部 所有內容,值 1 表示零件應完全反射。
反射率不受 BasePart.Transparency 影響,除非零件完全透明,否則反射率將完全部 所有失效。反射率可能會或可能不會被忽略,取決於零件的 BasePart.Material 。
範例程式碼
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
縮放增量屬性是一個只能閱讀的屬性,描述由 BasePart:Resize() 方法允許的最小尺寸變更。它與 BasePart 抽象類別的實現有所不同。例個體、實例,Part 設置為 1,而 TrussPart 設置為 2(因為個別桁架部分的尺寸為 2x2x2)。
範例程式碼
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
可縮放的面屬性(使用 e 而不是可縮放的面)描述使用面對象縮放零件上的不同面。對於大多數 BasePart 的實裝,例如 Part 和 WedgePart,此屬性包括所有面。然而, TrussPart 將將其可調整的面集合設為僅兩個面,因為這類零件必須有兩個BasePart.Size 長度為 2 的尺寸。此屬性最常用於用於建造和操縱零件的工具,在那之外的情況下使用量很少。擁有 Handles 屬性的 Handles.Faces 可以與此屬性結合,以顯示只有那些可以在零件上調整尺寸的面上的手柄。
範例程式碼
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
RightSurface 屬性決定了零件 +X 方向使用的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.RightSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型,包括鉸、馬達和步進馬達,會以 3D 裝飾代替。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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 之間的整數,優先於根部排序的所有其他規則。當考慮不是 Anchored 且共享相同 Massless 值的多個零件時,具有更高 根據優先級 的零件將會取代那些具有更低 根據優先級 的零件。
您可以使用此屬性來控制裝配中哪一部分是根部分,並在尺寸變更時保持根部分穩定。
也可以參閱裝配文章,該文件記錄了根部件是什麼以及如何使用它們。
Rotation
零件在三軸上的旋轉度。
當設置此屬性時,任何Welds或Motor6Ds連接到此部分的C0或C1屬性將被更新,以允許部分相對於任何其他部分移動。
焊接限制也會在移動工具動期間暫時停用並重新啟用。
Size
零件的 Size 屬性決定其 視覺 尺寸,而 ExtentsSize 代表物理引擎使用的實際尺寸,例如在 碰撞偵測 中。個別尺寸(長度、寬度、高度)可低至 0.001 和高至 2048。尺寸小於 0.05 的尺寸將以 視覺形式 來表示,如果零件的尺寸是 0.05。
零件的尺寸決定了其質量,由 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 方向使用的表面類型。當兩個零件的面積放置在一起時,它們可能會創建一個聯結在他們之間。如果設為引擎,BasePart.TopSurfaceInput 將決定引擎聯節應該如何行動。
大多數表面類型會在零件表面上渲染紋理,如果 BasePart.Material 設為塑膠。一些表面類型 - 鉸、馬達和步進馬達 - 會渲染 3D 裝飾。如果此屬性在屬性視窗中被選擇,它將在遊戲世界中與 SurfaceSelection 類似地被突出顯示。
範例程式碼
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
透明屬性控制零到一的比例上方部件的可見度,其中零完全可見(不透明),一值完全隱形(不被渲染)。
BasePart.Reflectance 可以將磚塊的整體透明度降低至接近 1 的值。
雖全部 所有完全透明的零件不會被渲染,但部分透明的對象有一些重要的渲染費用。擁有許多半透明零件可能會降低遊戲的履約。
當透明零件重疊時,渲染順序可能會變得不可預測 - 嘗試將半透明零件盡量不重疊,以避免這種情況。
BasePart.LocalTransparencyModifier 是對透明度的乘數,只對本地客戶可見。
範例程式碼
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() 。如果您可以修改/閱讀網絡所有權,它會返回真值;如果您無法修改/閱讀網絡所有權,它會返回 false,並將理由作為字串。
返回
無論您是否可以修改或閱讀網絡所有權和原因。
範例程式碼
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 是真的,這個函數將返回裝配中所有與基礎零件緊密連接的零件。
剛性聯節
當關節連接兩個零件一起時 (Part0 → Part1) , 關節是 剛性 如果物理學的 Part1 被 Part0 完全鎖定。這只適用於以下聯合類型:
參數
返回
GetJoints
返回連接到此零件的所有關節或限制。
返回
與零件連接的所有聯節或限制的一個數組。
GetMass
取得量 返回閱讀僅限的 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)
GetNoCollisionConstraints
返回
GetRootPart
返回裝配的基本部分。當使用 CFrame 移動零件組合時。移動此基礎零件(這將適當移動所有與它連接的其他零件)很重要。更多資訊可在 裝配 文章中找到。
此功能早於 AssemblyRootPart 屬性。它仍然支持退款,但您應該直接使用 AssemblyRootPart 。
返回
裝配的基本部分(一個連接在一起的零件集)。
GetTouchingParts
返回與此部分物理互動的所有零件的表。如果零件本身設置為「無法碰撞」為 false,則此函數將返回空表,除非零件有一個 TouchInterest 對象連接到它 (即意味著有東西連接到其觸碰事件)。相鄰但不相交的零件不會被視為接觸。此功能優先於 WorldRoot:GetPartsInPart() 功能,提供更多彈性並避免上述特殊 TouchInterest 規則所述的問題。使用 WorldRoot:GetPartsInPart() 取代。
返回
一個包含所有交叉部件,可能與此部件碰撞的表。
GetVelocityAtPosition
返回零件在指定位置相對於此零件的線速度。它可用於識別與根部零件不同的裝配中零件的線速度。如果裝配沒有角速度,則線速度將永遠一致於每個位置。
參數
返回
IsGrounded
如果對象連接到會將其保持在位置的零件(例如 Anchored 零件),則返回真值;否則返回假值。在裝配中包含 Anchored 零件的情況下,其他每個零件都被接地。
返回
物件是否連接到會將其保持在空間的零件。
Resize
以相同於使用 Studio 縮放工具的方式變更對象的大小。
參數
要縮調整大小的側面。
在指定的一側增長/縮小多少。
返回
零件是否已縮放。
SetNetworkOwner
將指定的玩家設為網絡所有者,用於此網絡和所有連接的零件。當玩家Instance是 nil 時,伺服器將成為玩家而不是玩家的所有者。
參數
給予玩家擁有零件網絡所有權。
返回
SetNetworkOwnershipAuto
讓遊戲引擎動態決定誰會處理零件的物理(客戶端之一或服務伺服器)。
返回
IntersectAsync
從零件和給定數陣列中的其他零件的交集幾何中創建一個新的 IntersectOperation 。只支持 Parts ,不支持 Terrain 或 MeshParts 。與 Clone() 類似,返回的對象沒有設置 Parent。
呼叫方的下列屬性將適用於結果的 IntersectOperation :
在下面的圖像比較中,IntersectAsync() 被稱為使用包含藍色方塊的表來調用紫色方磚塊。最終得到的 IntersectOperation 會轉化為兩個零件的交集幾何形狀。

<figcaption>分開零件</figcaption>

<figcaption>結果 <code>Class.IntersectOperation</code></figcaption>
注意事項
- 如果交叉操作會導致超過 20,000 個三角形的零件,將簡化為 20,000 個三角形。
參數
參與交叉的對象。
結果的 Enum.CollisionFidelity 值為 IntersectOperation 。
結果的 Enum.RenderFidelity 的 PartOperation。
返回
結果 IntersectOperation 使用預設名稱 交叉 。
SubtractAsync
從零件中創建一個新的 UnionOperation ,減去給定數陣列中零件所佔的幾何圖形。只支持 Parts ,不支持 Terrain 或 MeshParts 。與 Clone() 類似,返回的對象沒有設置 Parent。
請注意,由於減法造成的結果聯盟不能為空,如果操作會導致完全空白的幾何圖形,它將失敗。
在下面的圖像比較中,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 ,不支持 Terrain 或 MeshParts 。與 Clone() 類似,返回的對象沒有設置 Parent。
呼叫方的下列屬性將適用於結果的 UnionOperation :
在下面的圖像比較中,UnionAsync() 被稱為使用紫色圓筒的藍色方塊使用表中的表。最終得到的 UnionOperation 會轉化為兩個零件的組合幾何形狀。

<figcaption>分開零件</figcaption>

<figcaption>結果 <code>Class.UnionOperation</code></figcaption>
注意事項
- 如果聯合操作會導致超過 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 撞到 零件B ,則 PartA.Touched 使用 零件B 發射,而 PartB.Touched 使用 零件A 發射。
此事件只會在物理移動的結果發生,因此如果 CFrame 屬性被變更,使零件與另一零件重疊,就不會發生。這也意味著至少一個涉及的零件必須 不 在碰撞時 Anchored 。
這個事件與 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