Apprendre
Classe de moteur
AnimationTrack
Création impossible

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



Référence API
Propriétés
Animation
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
AnimationTrack.Animation:Animation
Échantillons de code
Écouter de nouvelles animations
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
animator.AnimationPlayed:Connect(function(animationTrack)
local animationName = animationTrack.Animation.Name
print("Animation en cours " .. animationName)
end)

IsPlaying
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.IsPlaying:boolean
Échantillons de code
AnimationTrack EstJouant
local function playOrAdjust(animationTrack, fadeTime, weight, speed)
if not animationTrack.IsPlaying then
animationTrack:Play(fadeTime, weight, speed)
else
animationTrack:AdjustSpeed(speed)
animationTrack:AdjustWeight(weight, fadeTime)
end
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playOrAdjust(animationTrack, 1, 0.6, 1)

Length
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
AnimationTrack.Length:number
Échantillons de code
Lecture d'une animation pendant une durée spécifique
local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

Looped
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.Looped:boolean
Échantillons de code
Boucle d'animation
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Looped = false
task.wait(3)
animationTrack:Play()
task.wait(4)
animationTrack.Looped = true
animationTrack:Play()
Lire AnimationTrack pour un nombre de boucles
local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("boucle : ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- il est important de déconnecter les connexions lorsqu'elles ne sont plus nécessaires
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)

Priority
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.Priority:Enum.AnimationPriority

Speed
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.Speed:number
Échantillons de code
Vitesse d'animation
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("À vitesse normale, l'animation durera", normalSpeedTime, "secondes")
print("À vitesse 3x, l'animation durera", fastSpeedTime, "secondes")
Lecture d'une animation pendant une durée spécifique
local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

TimePosition
Non répliqué
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.TimePosition:number
Échantillons de code
Geler l'animation à la position
function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Jouer l'animation si elle ne joue pas
animationTrack:Play()
end
-- Définir la vitesse à 0 pour geler l'animation
animationTrack:AdjustSpeed(0)
-- Sauter à la TimePosition souhaitée
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Jouer l'animation si elle ne joue pas
animationTrack:Play()
end
-- Définir la vitesse à 0 pour geler l'animation
animationTrack:AdjustSpeed(0)
-- Sauter à la TimePosition souhaitée
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

WeightCurrent
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.WeightCurrent:number
Échantillons de code
PoidsActuel et PoidsCible
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- temps d'attente arbitraire pour permettre au personnage de se mettre en place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("c'est fait")
done = true
end
end

WeightTarget
Lecture uniquement
Non répliqué
Lecture parallèle
Capacités : Animation
Accès à la simulation
AnimationTrack.WeightTarget:number
Échantillons de code
PoidsActuel et PoidsCible
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- temps d'attente arbitraire pour permettre au personnage de se mettre en place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("c'est fait")
done = true
end
end

Méthodes
AdjustSpeed
Capacités : Animation
Accès à la simulation
AnimationTrack:AdjustSpeed(speed:number):()
Paramètres
speed:number
Valeur par défaut : 1
Retours
()
Échantillons de code
Lecture d'une animation pendant une durée spécifique
local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)
Vitesse d'animation
local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("À vitesse normale, l'animation durera", normalSpeedTime, "secondes")
print("À vitesse 3x, l'animation durera", fastSpeedTime, "secondes")

AdjustWeight
Capacités : Animation
Accès à la simulation
AnimationTrack:AdjustWeight(
weight:number, fadeTime:number
):()
Paramètres
weight:number
Valeur par défaut : 1
fadeTime:number
Valeur par défaut : 0.100000001
Retours
()
Échantillons de code
AnimationTrack Changer de Poids
local function changeWeight(animationTrack, weight, fadeTime)
animationTrack:AdjustWeight(weight, fadeTime)
local startTime = tick()
while math.abs(animationTrack.WeightCurrent - weight) > 0.001 do
task.wait()
end
print("Temps pris pour changer le poids " .. tostring(tick() - startTime))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
changeWeight(animationTrack, 0.6, 1)

GetMarkerReachedSignal
Capacités : Animation
AnimationTrack:GetMarkerReachedSignal(name:string):RBXScriptSignal
Paramètres
name:string
Échantillons de code
Écoute des marqueurs clés
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Créer une nouvelle instance "Animation"
local kickAnimation = Instance.new("Animation")
-- Définir son "AnimationId" sur l'ID d'actif d'animation correspondant
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Charger l'animation sur le humanoïde
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
-- Jouer le morceau d'animation
kickAnimationTrack:Play()
-- Si un événement nommé a été défini pour l'animation, connectez-le à "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)

GetParameter
Capacités : Animation
Accès à la simulation
AnimationTrack:GetParameter(key:string):Variant
Paramètres
key:string
Retours
Variant

GetParameterDefaults
Capacités : Animation
AnimationTrack:GetParameterDefaults():Dictionary
Retours

GetTargetInstance
Capacités : Animation
AnimationTrack:GetTargetInstance(name:string):Instance?
Paramètres
name:string
Retours

GetTargetNames
Capacités : Animation
AnimationTrack:GetTargetNames():{any}
Retours

GetTimeOfKeyframe
Capacités : Animation
AnimationTrack:GetTimeOfKeyframe(keyframeName:string):number
Paramètres
keyframeName:string
Retours
Échantillons de code
Sauter à la clé
local function jumpToKeyframe(animationTrack, keyframeName)
local timePosition = animationTrack:GetTimeOfKeyframe(keyframeName)
if not animationTrack.IsPlaying then
animationTrack:Play()
end
animationTrack.TimePosition = timePosition
end
local ANIMATION_ID = 0
local KEYFRAME_NAME = "Test"
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. ANIMATION_ID
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
jumpToKeyframe(animationTrack, KEYFRAME_NAME)

Play
Capacités : Animation
Accès à la simulation
AnimationTrack:Play(
fadeTime:number, weight:number, speed:number
):()
Paramètres
fadeTime:number
Valeur par défaut : 0.100000001
weight:number
Valeur par défaut : 1
speed:number
Valeur par défaut : 1
Retours
()
Échantillons de code
Lecture d'une animation pendant une durée spécifique
local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)
Geler l'animation à la position
function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Jouer l'animation si elle ne joue pas
animationTrack:Play()
end
-- Définir la vitesse à 0 pour geler l'animation
animationTrack:AdjustSpeed(0)
-- Sauter à la TimePosition souhaitée
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Jouer l'animation si elle ne joue pas
animationTrack:Play()
end
-- Définir la vitesse à 0 pour geler l'animation
animationTrack:AdjustSpeed(0)
-- Sauter à la TimePosition souhaitée
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

SetParameter
Capacités : Animation
Accès à la simulation
AnimationTrack:SetParameter(
key:string, value:Variant
):()
Paramètres
key:string
value:Variant
Retours
()

SetTargetInstance
Capacités : Animation
AnimationTrack:SetTargetInstance(
name:string, target:Instance?
):()
Paramètres
name:string
target:Instance?
Retours
()

Stop
Capacités : Animation
Accès à la simulation
AnimationTrack:Stop(fadeTime:number):()
Paramètres
fadeTime:number
Valeur par défaut : 0.100000001
Retours
()
Échantillons de code
Arrêter AnimationTrack
local function fadeOut(animationTrack, fadeTime)
animationTrack:Stop(fadeTime)
local startTime = tick()
while animationTrack.WeightCurrent > 0 do
task.wait()
end
local timeTaken = tick() - startTime
print("Temps pris pour réinitialiser le poids : " .. tostring(timeTaken))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
fadeOut(animationTrack, 1)

Événements
DidLoop
Capacités : Animation
AnimationTrack.DidLoop():RBXScriptSignal
Échantillons de code
Lire AnimationTrack pour un nombre de boucles
local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("boucle : ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- il est important de déconnecter les connexions lorsqu'elles ne sont plus nécessaires
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)

Ended
Capacités : Animation
AnimationTrack.Ended():RBXScriptSignal
Échantillons de code
AnimationTrack Terminé
local InsertService = game:GetService("InsertService")
local Players = game:GetService("Players")
-- Créer un modèle NPC à animer.
local npcModel = Players:CreateHumanoidModelFromUserIdAsync(129687796)
npcModel.Name = "JoeNPC"
npcModel.Parent = workspace
npcModel:MoveTo(Vector3.new(0, 15, 4))
local humanoid = npcModel:WaitForChild("Humanoid")
-- Charger une animation.
local animationModel = InsertService:LoadAsset(2510238627)
local animation = animationModel:FindFirstChildWhichIsA("Animation", true)
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
-- Se connecter à l'événement Stopped. Cela se déclenche lorsque l'animation s'arrête de
-- son propre chef, ou que nous appelons explicitement Stop.
animationTrack.Stopped:Connect(function()
print("Animation arrêtée")
end)
-- Se connecter à l'événement Ended. Cela se déclenche lorsque l'animation est complètement
-- finie d'affecter le monde. Dans ce cas, cela se déclenchera 3 secondes
-- après que nous ayons appelé animationTrack:Stop car nous passons un
-- fondu de 3 secondes.
animationTrack.Ended:Connect(function()
print("Animation terminée")
animationTrack:Destroy()
end)
-- Exécuter, laissez-le jouer un peu, puis arrêtez.
print("Appel de Play")
animationTrack:Play()
task.wait(10)
print("Appel de Stop")
animationTrack:Stop(3)

KeyframeReached
Déprécié

Stopped
Capacités : Animation
AnimationTrack.Stopped():RBXScriptSignal
Échantillons de code
AnimationTrack Arrêté
local function yieldPlayAnimation(animationTrack, fadeTime, weight, speed)
animationTrack:Play(fadeTime, weight, speed)
animationTrack.Stopped:Wait()
print("L'animation s'est arrêtée")
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
yieldPlayAnimation(animationTrack, 1, 0.6, 1)

©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.