概要
方法
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
-- 我們只對 Motor6D 感興趣
\
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
範例程式碼
獲取 KeyframeSequence 長度
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) --標記.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(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
-- 我們只對 Motor6D 感興趣
\
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) --標記的父級 = keyframe
keyframe:AddMarker(marker2) --標記的父級 = 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) --標記.Parent = keyframe
task.wait(2)
keyframe:RemoveMarker(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