エンジンクラス
Keyframe
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
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")
-- キーフレームを populate
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
-- 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")
-- キーフレームを populate
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 = "足音"
marker1.Value = 100
local marker2 = Instance.new("KeyframeMarker")
marker2.Name = "波"
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