学习
引擎类
Pose

*此内容使用人工智能(Beta)翻译,可能包含错误。若要查看英文页面,请点按 此处


概要
方法
GetSubPoses():Instances
继承成员
代码示例
关键帧生成姿势
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("未设置主要部件")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("未找到根部件")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- 获取连接到该部件的所有关节
for _, joint in pairs(part:GetJoints()) do
-- 我们只对 Motor6Ds 感兴趣
if joint:IsA("Motor6D") then
-- 找到连接的部件
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- 确保我们尚未添加此部件
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- 创建一个姿势
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- 递归
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- 填充关键帧
local rootPose = Instance.new("Pose")
rootPose.Name = rootPart.Name
addPoses(rootPart, rootPose)
keyframe:AddPose(rootPose)
return keyframe
end
local character = script.Parent
local keyframe = generateKeyframe(character)
print(keyframe)
关键帧重置姿势
local function resetPoses(parent)
-- 两个函数等效于 GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- 递归
resetPoses(pose)
end
end
end

API 参考
属性
CFrame
读取并联
功能: Animation
Pose.CFrame:CFrame

MaskWeight
已弃用

方法
AddSubPose
功能: Animation
Pose:AddSubPose(pose:Instance):()
参数
返回
()
代码示例
关键帧添加/移除姿势
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil

GetSubPoses
功能: Animation
Pose:GetSubPoses():Instances
返回
Instances
代码示例
关键帧重置姿势
local function resetPoses(parent)
-- 两个函数等效于 GetChildren
local poses = parent:IsA("Keyframe") and parent:GetPoses() or parent:IsA("Pose") and parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- 递归
resetPoses(pose)
end
end
end

RemoveSubPose
功能: Animation
Pose:RemoveSubPose(pose:Instance):()
参数
返回
()
代码示例
关键帧添加/移除姿势
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local pose = Instance.new("Pose")
pose.EasingStyle = Enum.PoseEasingStyle.Cubic
pose.EasingDirection = Enum.PoseEasingDirection.Out
local pose2 = Instance.new("Pose")
pose2.EasingStyle = Enum.PoseEasingStyle.Cubic
pose2.EasingDirection = Enum.PoseEasingDirection.Out
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
keyframe:RemovePose(pose) -- pose.Parent = nil
task.wait(2)
keyframe:AddPose(pose) -- pose.Parent = keyframe
task.wait(2)
pose:AddSubPose(pose2) -- pose2.Parent = pose
task.wait(2)
pose:RemoveSubPose(pose2) -- pose2.Parent = nil

©2026 Roblox Corporation、Roblox、Roblox 标志及 Powering Imagination 是我们在美国及其他国家或地区的注册与未注册商标。