เรียนรู้
Engine Class
Keyframe

*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่


สรุป
คุณสมบัติ
วิธีการ
AddMarker(marker: Instance):()
AddPose(pose: Instance):()
สมาชิกที่ได้รับทอด
ตัวอย่างโค้ด
การสร้างท่าใน Keyframe
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")
-- เติมข้อมูลใน 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
อ่านพร้อมๆ กัน
ความสามารถ: Animation
Keyframe.Time:number
ตัวอย่างโค้ด
ความยาวของ 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
ความสามารถ: Animation
Keyframe:AddMarker(marker:Instance):()
พารามิเตอร์
marker:Instance
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เพิ่มเครื่องหมาย/ลบเครื่องหมาย
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 = nil

AddPose
ความสามารถ: Animation
Keyframe:AddPose(pose:Instance):()
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
การสร้างท่าใน Keyframe
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")
-- เติมข้อมูลใน 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)
เพิ่ม/ลบท่าทาง 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 = nil

GetMarkers
ความสามารถ: Animation
Keyframe:GetMarkers():{KeyframeMarker}
ส่งค่ากลับ
ตัวอย่างโค้ด
รับตัวชี้กุญแจที่แนบมากับกุญแจ
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) --พิมพ์ชื่อของตัวชี้
end

GetPoses
ความสามารถ: Animation
Keyframe:GetPoses():{Pose}
ส่งค่ากลับ
ตัวอย่างโค้ด
การรีเซ็ตท่าทาง Keyframe
local function resetPoses(parent)
-- ฟังก์ชันทั้งสองนี้เทียบเท่ากับ GetChildren
local poses = parent:IsA("Keyframe") และ parent:GetPoses() หรือ parent:IsA("Pose") และ parent:GetSubPoses()
for _, pose in pairs(poses) do
if pose:IsA("Pose") then
pose.CFrame = CFrame.new()
-- ทำซ้ำ
resetPoses(pose)
end
end
end

RemoveMarker
ความสามารถ: Animation
Keyframe:RemoveMarker(marker:Instance):()
พารามิเตอร์
marker:Instance
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เพิ่มเครื่องหมาย/ลบเครื่องหมาย
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 = nil

RemovePose
ความสามารถ: Animation
Keyframe:RemovePose(pose:Instance):()
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
เพิ่ม/ลบท่าทาง 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 = nil

©2026 Roblox Corporation. Roblox, โลโก้ Roblox และ Powering Imagination เป็นส่วนหนึ่งของเครื่องหมายการค้าที่จดทะเบียน และไม่ได้จดทะเบียนของเราในสหรัฐฯ และประเทศอื่นๆ