概要
方法
RemoveMarker(marker: Instance):() |
RemovePose(pose: Instance):() |
代码示例
关键帧生成姿势
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)API 参考
属性
Time
代码示例
获取关键帧序列长度
local function getSequenceLength(keyframeSequence)
local length = 0
for _, keyframe in pairs(keyframeSequence:GetKeyframes()) do
if keyframe.Time > length then
length = keyframe.Time
end
end
return length
end
local keyframeSequence = Instance.new("KeyframeSequence")
getSequenceLength(keyframeSequence)方法
AddMarker
参数
返回
()
代码示例
添加标记/移除标记
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nilAddPose
参数
返回
()
代码示例
关键帧生成姿势
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 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 = nilGetMarkers
返回
代码示例
获取附加到关键帧的关键帧标记
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker1 = Instance.new("KeyframeMarker")
marker1.Name = "FootStep"
marker1.Value = 100
local marker2 = Instance.new("KeyframeMarker")
marker2.Name = "Wave"
marker2.Value = 100
keyframe:AddMarker(marker1) --marker.Parent = keyframe
keyframe:AddMarker(marker2) --marker.Parent = keyframe
local markers = keyframe:GetMarkers()
for _, marker in pairs(markers) do
print(marker.Name)
endGetPoses
返回
{Pose}
代码示例
关键帧重置姿势
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
endRemoveMarker
参数
返回
()
代码示例
添加标记/移除标记
local keyframe = Instance.new("Keyframe")
keyframe.Parent = workspace
local marker = Instance.new("KeyframeMarker")
marker.Name = "FootStep"
marker.Value = 100
keyframe:AddMarker(marker) --marker.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(marker) --marker.Parent = nilRemovePose
参数
返回
()
代码示例
关键帧添加/移除姿势
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