Apprendre
Classe de moteur
Keyframe

*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.


Résumé
Propriétés
Membres hérités
Échantillons de code
Générer des poses de keyframe
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("Aucune partie principale définie")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Partie racine non trouvée")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- récupérer toutes les articulations attachées à la partie
for _, joint in pairs(part:GetJoints()) do
-- nous ne nous intéressons qu'aux Motor6Ds
if joint:IsA("Motor6D") then
-- trouver la partie connectée
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- s'assurer que nous n'avons pas déjà ajouté cette partie
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- créer une pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- récursif
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- peupler le 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)

Référence API
Propriétés
Time
Lecture parallèle
Capacités : Animation
Keyframe.Time:number
Échantillons de code
Obtenir la longueur de 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)

Méthodes
AddMarker
Capacités : Animation
Keyframe:AddMarker(marker:Instance):()
Paramètres
marker:Instance
Retours
()
Échantillons de code
Ajouter un marqueur/Retirer un marqueur
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
Capacités : Animation
Keyframe:AddPose(pose:Instance):()
Paramètres
Retours
()
Échantillons de code
Générer des poses de keyframe
local function generateKeyframe(model)
if not model.PrimaryPart then
warn("Aucune partie principale définie")
return
end
local rootPart = model.PrimaryPart:GetRootPart()
if not rootPart then
warn("Partie racine non trouvée")
return
end
local partsAdded = {}
partsAdded[rootPart] = true
local function addPoses(part, parentPose)
-- récupérer toutes les articulations attachées à la partie
for _, joint in pairs(part:GetJoints()) do
-- nous ne nous intéressons qu'aux Motor6Ds
if joint:IsA("Motor6D") then
-- trouver la partie connectée
local connectedPart = nil
if joint.Part0 == part then
connectedPart = joint.Part1
elseif joint.Part1 == part then
connectedPart = joint.Part0
end
if connectedPart then
-- s'assurer que nous n'avons pas déjà ajouté cette partie
if not partsAdded[connectedPart] then
partsAdded[connectedPart] = true
-- créer une pose
local pose = Instance.new("Pose")
pose.Name = connectedPart.Name
parentPose:AddSubPose(pose)
-- récursif
addPoses(connectedPart, pose)
end
end
end
end
end
local keyframe = Instance.new("Keyframe")
-- peupler le 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)
Ajout/Retrait de Pose de 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
Capacités : Animation
Keyframe:GetMarkers():{KeyframeMarker}
Échantillons de code
Obtenir des marqueurs de keyframe attachés à un keyframe
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
Capacités : Animation
Keyframe:GetPoses():{Pose}
Retours
Échantillons de code
Réinitialiser les poses de keyframe
local function resetPoses(parent)
-- les deux fonctions sont équivalentes à 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()
-- récursive
resetPoses(pose)
end
end
end

RemoveMarker
Capacités : Animation
Keyframe:RemoveMarker(marker:Instance):()
Paramètres
marker:Instance
Retours
()
Échantillons de code
Ajouter un marqueur/Retirer un marqueur
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
Capacités : Animation
Keyframe:RemovePose(pose:Instance):()
Paramètres
Retours
()
Échantillons de code
Ajout/Retrait de Pose de 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 Société Roblox. Roblox, le logo Roblox et Powering Imagination font partie de nos marques déposées aux États-Unis et dans d'autres pays.