學習
引擎類別
BasePart
無法建立
無法瀏覽

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡


概要
屬性
BackParamA:number
已棄用
BackParamB:number
已棄用
Elasticity:number
已棄用
Friction:number
已棄用
LeftParamA:number
已棄用
LeftParamB:number
已棄用
TopParamA:number
已棄用
TopParamB:number
已棄用
Velocity:Vector3
已棄用
方法
AngularAccelerationToTorque(angAcceleration: Vector3,angVelocity: Vector3):Vector3
ApplyImpulse(impulse: Vector3):()
ApplyImpulseAtPosition(impulse: Vector3,position: Vector3):()
BreakJoints():()
已棄用
breakJoints():()
已棄用
GetJoints():Instances
getMass():number
已棄用
GetRootPart():Instance
已棄用
GetTouchingParts():Instances
IntersectAsync(parts: Instances,collisionfidelity: Enum.CollisionFidelity,renderFidelity: Enum.RenderFidelity):Instance
MakeJoints():()
已棄用
makeJoints():()
已棄用
Resize(normalId: Enum.NormalId,deltaAmount: number):boolean
resize(normalId: Enum.NormalId,deltaAmount: number):boolean
已棄用
SetNetworkOwner(playerInstance: Player):()
SubtractAsync(parts: Instances,collisionfidelity: Enum.CollisionFidelity,renderFidelity: Enum.RenderFidelity):Instance
UnionAsync(parts: Instances,collisionfidelity: Enum.CollisionFidelity,renderFidelity: Enum.RenderFidelity):Instance
繼承成員
範例程式碼
平滑阻尼一個物件的 CFrame
local TweenService = game:GetService("TweenService")
-- 創建一個部件和目標
local part = Instance.new("Part", workspace)
part.Size = Vector3.one
part.Anchored = true
part.BrickColor = BrickColor.new("Electric blue")
part.CFrame = CFrame.new(0, 4, 0)
local target = Instance.new("Part", workspace)
target.Name = "Target"
target.Size = Vector3.one * 0.5
target.Anchored = true
target.BrickColor = BrickColor.new("Really red")
target.CFrame = CFrame.new(0, 8, 0)
-- 設定一個變數來儲存速度
local velocity = CFrame.new()
-- 調整平滑速度
local smoothTime = 0.5
game:GetService("RunService").Stepped:Connect(function(t, dt)
part.CFrame, velocity = TweenService:SmoothDamp(part.CFrame, target.CFrame, velocity, smoothTime, math.huge, dt)
end)

API 參考
屬性
Anchored
平行讀取
模擬存取權
BasePart.Anchored:boolean
範例程式碼
部件固定切換
local part = script.Parent
-- 創建一個 ClickDetector,以便我們知道部件何時被點擊
local cd = Instance.new("ClickDetector", part)
-- 這個函數根據部件的固定狀態更新其外觀
local function updateVisuals()
if part.Anchored then
-- 當部件被固定時...
part.BrickColor = BrickColor.new("Bright red")
part.Material = Enum.Material.DiamondPlate
else
-- 當部件未固定時...
part.BrickColor = BrickColor.new("Bright yellow")
part.Material = Enum.Material.Wood
end
end
local function onToggle()
-- 切換固定屬性
part.Anchored = not part.Anchored
-- 更新磚塊的視覺狀態
updateVisuals()
end
-- 更新,然後開始監聽點擊事件
updateVisuals()
cd.MouseClick:Connect(onToggle)

AssemblyAngularVelocity
未複製
平行讀取
模擬存取權
BasePart.AssemblyAngularVelocity:Vector3

AssemblyCenterOfMass
唯讀
未複製
平行讀取
模擬存取權
BasePart.AssemblyCenterOfMass:Vector3

AssemblyLinearVelocity
未複製
平行讀取
模擬存取權
BasePart.AssemblyLinearVelocity:Vector3

AssemblyMass
唯讀
未複製
平行讀取
模擬存取權
BasePart.AssemblyMass:number

AssemblyRootPart
唯讀
未複製
平行讀取
模擬存取權
BasePart.AssemblyRootPart:BasePart

AudioCanCollide
平行讀取
模擬存取權
BasePart.AudioCanCollide:boolean

BackParamA
已棄用

BackParamB
已棄用

BackSurface
平行讀取
BasePart.BackSurface:Enum.SurfaceType

BackSurfaceInput
已棄用

BottomParamA
已棄用

BottomParamB
已棄用

BottomSurface
平行讀取
BasePart.BottomSurface:Enum.SurfaceType

BottomSurfaceInput
已棄用

BrickColor
未複製
平行讀取
BasePart.BrickColor:BrickColor

brickColor
已棄用

CanCollide
平行讀取
模擬存取權
BasePart.CanCollide:boolean
範例程式碼
淡化門
-- 貼到一個高部件內的腳本
local part = script.Parent
local OPEN_TIME = 1
-- 現在可以打開門嗎?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("黑色")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("亮藍色")
end
local function onTouch(otherPart)
-- 如果門已經打開,什麼都不做
if debounce then
print("D")
return
end
-- 檢查是否被 humanoid 觸碰
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("不是 humanoid")
return
end
-- 執行開門序列
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()

CanQuery
平行讀取
模擬存取權
BasePart.CanQuery:boolean

CanTouch
平行讀取
模擬存取權
BasePart.CanTouch:boolean

CastShadow
平行讀取
BasePart.CastShadow:boolean

CenterOfMass
唯讀
未複製
平行讀取
模擬存取權
BasePart.CenterOfMass:Vector3

CFrame
平行讀取
模擬存取權
BasePart.CFrame:CFrame
範例程式碼
設定部件的 CFrame
local part = script.Parent:WaitForChild("Part")
local otherPart = script.Parent:WaitForChild("OtherPart")
-- 將部件的 CFrame 重置為 (0, 0, 0) 並沒有旋轉。
-- 這有時被稱為「身份」CFrame
part.CFrame = CFrame.new()
-- 設定為特定位置 (X, Y, Z)
part.CFrame = CFrame.new(0, 25, 10)
-- 與上面相同,但使用 Vector3
local point = Vector3.new(0, 25, 10)
part.CFrame = CFrame.new(point)
-- 設定部件的 CFrame 在某個點,看向另一個點
local lookAtPoint = Vector3.new(0, 20, 15)
part.CFrame = CFrame.lookAt(point, lookAtPoint)
-- 在本地 X 軸上將部件的 CFrame 旋轉 pi/2 弧度
part.CFrame = part.CFrame * CFrame.Angles(math.pi / 2, 0, 0)
-- 在本地 Y 軸上將部件的 CFrame 旋轉 45 度
part.CFrame = part.CFrame * CFrame.Angles(0, math.rad(45), 0)
-- 在全局 Z 軸上將部件的 CFrame 旋轉 180 度(注意順序!)
part.CFrame = CFrame.Angles(0, 0, math.pi) * part.CFrame -- Pi 弧度等於 180 度
-- 組合兩個 CFrame 是使用 *(乘法運算符)
part.CFrame = CFrame.new(2, 3, 4) * CFrame.new(4, 5, 6) --> 等於 CFrame.new(6, 8, 10)
-- 與代數乘法不同,CFrame 組合不是交換的:a * b 不一定等於 b * a!
-- 想像 * 為一系列有序的動作。例如,以下幾行會產生不同的 CFrame:
-- 1) 在 X 軸上平移部件 5 個單位。
-- 2) 將部件繞其 Y 軸旋轉 45 度。
part.CFrame = CFrame.new(5, 0, 0) * CFrame.Angles(0, math.rad(45), 0)
-- 1) 將部件繞其 Y 軸旋轉 45 度。
-- 2) 在 X 軸上平移部件 5 個單位。
part.CFrame = CFrame.Angles(0, math.rad(45), 0) * CFrame.new(5, 0, 0)
-- 沒有「CFrame 除法」,而是簡單地「執行相反操作」。
part.CFrame = CFrame.new(4, 5, 6) * CFrame.new(4, 5, 6):Inverse() --> 等於 CFrame.new(0, 0, 0)
part.CFrame = CFrame.Angles(0, 0, math.pi) * CFrame.Angles(0, 0, math.pi):Inverse() --> 等於 CFrame.Angles(0, 0, 0)
-- 相對於另一個部件設定位置(在這個案例中,將我們的部件放在 otherPart 上方)
part.CFrame = otherPart.CFrame * CFrame.new(0, part.Size.Y / 2 + otherPart.Size.Y / 2, 0)

CollisionGroup
未複製
平行讀取
模擬存取權
BasePart.CollisionGroup:string
範例程式碼
物理服務:註冊碰撞組
local PhysicsService = game:GetService("PhysicsService")
local collisionGroupBall = "CollisionGroupBall"
local collisionGroupDoor = "CollisionGroupDoor"
-- 註冊碰撞組
PhysicsService:RegisterCollisionGroup(collisionGroupBall)
PhysicsService:RegisterCollisionGroup(collisionGroupDoor)
-- 將部件分配到碰撞組
script.Parent.BallPart.CollisionGroup = collisionGroupBall
script.Parent.DoorPart.CollisionGroup = collisionGroupDoor
-- 將組設置為不可互撞,並檢查結果
PhysicsService:CollisionGroupSetCollidable(collisionGroupBall, collisionGroupDoor,
false)
print(PhysicsService:CollisionGroupsAreCollidable(collisionGroupBall, collisionGroupDoor))
--> false

CollisionGroupId
已棄用

Color
未複製
平行讀取
BasePart.Color:Color3
範例程式碼
角色健康身體顏色
-- 將它粘貼到 StarterCharacterScripts 內的腳本中
-- 然後玩遊戲,並調整你的角色健康
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
-- 根據你的健康百分比生成顏色
-- 顏色從 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
唯讀
未複製
平行讀取
BasePart.CurrentPhysicalProperties:PhysicalProperties

CustomPhysicalProperties
平行讀取
模擬存取權
BasePart.CustomPhysicalProperties:PhysicalProperties
範例程式碼
設置自訂物理屬性
local part = script.Parent
-- 這會使零件變得輕且有彈性!
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

Elasticity
已棄用

EnableFluidForces
平行讀取
模擬存取權
BasePart.EnableFluidForces:boolean

ExtentsCFrame
唯讀
未複製
平行讀取
模擬存取權
BasePart.ExtentsCFrame:CFrame

ExtentsSize
唯讀
未複製
平行讀取
模擬存取權
BasePart.ExtentsSize:Vector3

Friction
已棄用

FrontParamA
已棄用

FrontParamB
已棄用

FrontSurface
平行讀取
BasePart.FrontSurface:Enum.SurfaceType

FrontSurfaceInput
已棄用

LeftParamA
已棄用

LeftParamB
已棄用

LeftSurface
平行讀取
BasePart.LeftSurface:Enum.SurfaceType

LeftSurfaceInput
已棄用

LocalTransparencyModifier
隱藏
未複製
平行讀取
BasePart.LocalTransparencyModifier:number

Locked
平行讀取
模擬存取權
BasePart.Locked:boolean
範例程式碼
遞迴解鎖
-- 粘貼到您想要解鎖的模型中的腳本
local model = script.Parent
-- 此函數遍歷模型的階層並解鎖
-- 每個遇到的部分。
local function recursiveUnlock(object)
if object:IsA("BasePart") then
object.Locked = false
end
-- 在物件的子物件中調用相同的函數
-- 當物件沒有子物件時,遞迴過程將停止
for _, child in pairs(object:GetChildren()) do
recursiveUnlock(child)
end
end
recursiveUnlock(model)

Mass
唯讀
未複製
平行讀取
模擬存取權
BasePart.Mass:number

Massless
平行讀取
模擬存取權
BasePart.Massless:boolean

Material
平行讀取
模擬存取權
BasePart.Material:Enum.Material

MaterialVariant
未複製
平行讀取
模擬存取權
BasePart.MaterialVariant:string

Orientation
隱藏
未複製
平行讀取
模擬存取權
BasePart.Orientation:Vector3
範例程式碼
部件旋轉器
local part = script.Parent
local INCREMENT = 360 / 20
-- 不斷旋轉 部件
while true do
for degrees = 0, 360, INCREMENT do
-- 僅設置 Y 軸的旋轉
part.Rotation = Vector3.new(0, degrees, 0)
-- 更好的方法是設置 CFrame
--part.CFrame = CFrame.new(part.Position) * CFrame.Angles(0, math.rad(degrees), 0)
task.wait()
end
end

PivotOffset
平行讀取
模擬存取權
BasePart.PivotOffset:CFrame
範例程式碼
重置樞紐
-- 定義函數以重置樞紐
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)
時鐘指針
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
-- 創建表盤
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
-- 創建時針
local hourHand = createHand(7, 1, 0)
local minuteHand = createHand(10, 0.6, 0.1)
local secondHand = createHand(11, 0.2, 0.2)
-- 啟動時鐘
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
隱藏
未複製
平行讀取
模擬存取權
BasePart.Position:Vector3

ReceiveAge
隱藏
唯讀
未複製
平行讀取
BasePart.ReceiveAge:number

Reflectance
平行讀取
BasePart.Reflectance:number

ResizeableFaces
唯讀
未複製
平行讀取
BasePart.ResizeableFaces:Faces
範例程式碼
調整手柄
-- 將此腳本放在幾種基本零件中,例如
-- Part, TrussPart, WedgePart, CornerWedgePart 等。
local part = script.Parent
-- 為此零件創建一個手柄對象
local handles = Instance.new("Handles")
handles.Adornee = part
handles.Parent = part
-- 手動指定適用於此手柄的面
handles.Faces = Faces.new(Enum.NormalId.Top, Enum.NormalId.Front, Enum.NormalId.Left)
-- 或者,使用可以調整大小的面。
-- 如果零件是只有兩個大小維度的 TrussPart,
-- 那麼可調整大小的面將只有兩個
-- 啟用的面。對於其他零件,所有面將被啟用。
handles.Faces = part.ResizeableFaces

ResizeIncrement
唯讀
未複製
平行讀取
BasePart.ResizeIncrement:number

RightParamA
已棄用

RightParamB
已棄用

RightSurface
平行讀取
BasePart.RightSurface:Enum.SurfaceType

RightSurfaceInput
已棄用

RootPriority
平行讀取
BasePart.RootPriority:number

Rotation
未複製
平行讀取
模擬存取權
BasePart.Rotation:Vector3

RotVelocity
已棄用

Size
未複製
平行讀取
模擬存取權
BasePart.Size:Vector3
範例程式碼
金字塔建造者
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
-- 從 color0 和 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

SpecificGravity
已棄用

TopParamA
已棄用

TopParamB
已棄用

TopSurface
平行讀取
BasePart.TopSurface:Enum.SurfaceType

TopSurfaceInput
已棄用

Transparency
平行讀取
BasePart.Transparency:number
範例程式碼
淡化門
-- 貼到一個高部件內的腳本
local part = script.Parent
local OPEN_TIME = 1
-- 現在可以打開門嗎?
local debounce = false
local function open()
part.CanCollide = false
part.Transparency = 0.7
part.BrickColor = BrickColor.new("黑色")
end
local function close()
part.CanCollide = true
part.Transparency = 0
part.BrickColor = BrickColor.new("亮藍色")
end
local function onTouch(otherPart)
-- 如果門已經打開,什麼都不做
if debounce then
print("D")
return
end
-- 檢查是否被 humanoid 觸碰
local human = otherPart.Parent:FindFirstChildOfClass("Humanoid")
if not human then
print("不是 humanoid")
return
end
-- 執行開門序列
debounce = true
open()
task.wait(OPEN_TIME)
close()
debounce = false
end
part.Touched:Connect(onTouch)
close()

Velocity
已棄用

方法
AngularAccelerationToTorque
模擬存取權
BasePart:AngularAccelerationToTorque(
angAcceleration:Vector3, angVelocity:Vector3
參數
angAcceleration:Vector3
angVelocity:Vector3
預設值:"0, 0, 0"
返回

ApplyAngularImpulse
模擬存取權
BasePart:ApplyAngularImpulse(impulse:Vector3):()
參數
impulse:Vector3
返回
()

ApplyImpulse
模擬存取權
BasePart:ApplyImpulse(impulse:Vector3):()
參數
impulse:Vector3
返回
()

ApplyImpulseAtPosition
模擬存取權
BasePart:ApplyImpulseAtPosition(
impulse:Vector3, position:Vector3
):()
參數
impulse:Vector3
position:Vector3
返回
()

BreakJoints
已棄用

breakJoints
已棄用

CanCollideWith
平行寫入
模擬存取權
BasePart:CanCollideWith(part:BasePart):boolean
參數
返回

CanSetNetworkOwnership
模擬存取權
BasePart:CanSetNetworkOwnership():Tuple
返回
範例程式碼
檢查是否可以設定零件的網路擁有權
local part = workspace:FindFirstChild("Part")
if part and part:IsA("BasePart") then
local canSet, errorReason = part:CanSetNetworkOwnership()
if canSet then
print(part:GetFullName() .. " 的網路擁有權可以更改!")
else
warn("無法更改 " .. part:GetFullName() .. " 的網路擁有權,原因是:" .. errorReason)
end
end

GetClosestPointOnSurface
模擬存取權
BasePart:GetClosestPointOnSurface(position:Vector3):Vector3
參數
position:Vector3
返回

GetConnectedParts
平行寫入
BasePart:GetConnectedParts(recursive:boolean):{BasePart}
參數
recursive:boolean
預設值:false
返回

GetJoints
平行寫入
模擬存取權
BasePart:GetJoints():Instances
返回
Instances

GetMass
平行寫入
模擬存取權
BasePart:GetMass():number
返回
範例程式碼
查找零件的質量
local myPart = Instance.new("Part")
myPart.Size = Vector3.new(4, 6, 4)
myPart.Anchored = true
myPart.Parent = workspace
local myMass = myPart:GetMass()
print("我的零件的質量是 " .. myMass)

getMass
已棄用

GetNetworkOwner
平行寫入
模擬存取權
BasePart:GetNetworkOwner():Instance
返回

GetNetworkOwnershipAuto
平行寫入
模擬存取權
BasePart:GetNetworkOwnershipAuto():boolean
返回

GetNoCollisionConstraints
模擬存取權
BasePart:GetNoCollisionConstraints():Instances
返回
Instances

GetRenderCFrame
已棄用

GetRootPart
已棄用

GetTouchingParts
模擬存取權
BasePart:GetTouchingParts():Instances
返回
Instances

GetVelocityAtPosition
平行寫入
模擬存取權
BasePart:GetVelocityAtPosition(position:Vector3):Vector3
參數
position:Vector3
返回

IntersectAsync
暫停
功能: CSG
BasePart:IntersectAsync(
parts:Instances, collisionfidelity:Enum.CollisionFidelity, renderFidelity:Enum.RenderFidelity
參數
parts:Instances
collisionfidelity:Enum.CollisionFidelity
預設值:"Default"
renderFidelity:Enum.RenderFidelity
預設值:"Automatic"
返回

IsGrounded
平行寫入
模擬存取權
BasePart:IsGrounded():boolean
返回

MakeJoints
已棄用

makeJoints
已棄用

Resize
模擬存取權
BasePart:Resize(
normalId:Enum.NormalId, deltaAmount:number
參數
normalId:Enum.NormalId
deltaAmount:number
返回

resize
已棄用

SetNetworkOwner
模擬存取權
BasePart:SetNetworkOwner(playerInstance:Player):()
參數
playerInstance:Player
預設值:"nil"
返回
()

SetNetworkOwnershipAuto
模擬存取權
BasePart:SetNetworkOwnershipAuto():()
返回
()

SubtractAsync
暫停
功能: CSG
BasePart:SubtractAsync(
parts:Instances, collisionfidelity:Enum.CollisionFidelity, renderFidelity:Enum.RenderFidelity
參數
parts:Instances
collisionfidelity:Enum.CollisionFidelity
預設值:"Default"
renderFidelity:Enum.RenderFidelity
預設值:"Automatic"
返回
範例程式碼
BasePart:SubtractAsync()
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- 執行減法運算
local success, newSubtract = pcall(function()
return mainPart:SubtractAsync(otherParts)
end)
-- 如果操作成功,將其放置在相同位置並將其父物件設為工作區
if success and newSubtract then
newSubtract.Position = mainPart.Position
newSubtract.Parent = Workspace
end
-- 銷毀操作後仍保持不變的原始零件
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end

TorqueToAngularAcceleration
模擬存取權
BasePart:TorqueToAngularAcceleration(
torque:Vector3, angVelocity:Vector3
參數
torque:Vector3
angVelocity:Vector3
預設值:"0, 0, 0"
返回

UnionAsync
暫停
功能: CSG
BasePart:UnionAsync(
parts:Instances, collisionfidelity:Enum.CollisionFidelity, renderFidelity:Enum.RenderFidelity
參數
parts:Instances
collisionfidelity:Enum.CollisionFidelity
預設值:"Default"
renderFidelity:Enum.RenderFidelity
預設值:"Automatic"
返回
範例程式碼
BasePart:UnionAsync()
local Workspace = game:GetService("Workspace")
local mainPart = script.Parent.PartA
local otherParts = { script.Parent.PartB, script.Parent.PartC }
-- 執行聯合操作
local success, newUnion = pcall(function()
return mainPart:UnionAsync(otherParts)
end)
-- 如果操作成功,將其放置在相同位置並將其父對象設置為工作空間
if success and newUnion then
newUnion.Position = mainPart.Position
newUnion.Parent = Workspace
end
-- 銷毀剩餘的原始部件
mainPart:Destroy()
for _, part in otherParts do
part:Destroy()
end

活動
LocalSimulationTouched
已棄用

OutfitChanged
已棄用

StoppedTouching
已棄用

Touched
BasePart.Touched(otherPart:BasePart):RBXScriptSignal
參數
otherPart:BasePart
範例程式碼
碰觸部件數量
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("觸碰開始: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("觸碰結束: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)
模型觸碰
local model = script.Parent
local function onTouched(otherPart)
-- 忽略模型與自身接觸的實例
if otherPart:IsDescendantOf(model) then
return
end
print(model.Name .. " 與 " .. otherPart.Name .. " 發生碰撞")
end
for _, child in pairs(model:GetChildren()) do
if child:IsA("BasePart") then
child.Touched:Connect(onTouched)
end
end

TouchEnded
BasePart.TouchEnded(otherPart:BasePart):RBXScriptSignal
參數
otherPart:BasePart
範例程式碼
碰觸部件數量
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("觸碰開始: " .. otherPart.Name)
numTouchingParts = numTouchingParts + 1
tl.Text = numTouchingParts
end
local function onTouchEnded(otherPart)
print("觸碰結束: " .. otherPart.Name)
numTouchingParts = numTouchingParts - 1
tl.Text = numTouchingParts
end
part.Touched:Connect(onTouch)
part.TouchEnded:Connect(onTouchEnded)

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。