Lernen
Engine-Klasse
AnimationTrack
Nicht erstellbar

*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.



API-Referenz
Eigenschaften
Animation
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
AnimationTrack.Animation:Animation
Code-Beispiele
Auf neue Animationen hören
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
animator.AnimationPlayed:Connect(function(animationTrack)
local animationName = animationTrack.Animation.Name
print("Animation wird abgespielt: " .. animationName)
end)

IsPlaying
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.IsPlaying:boolean
Code-Beispiele
AnimationTrack läuft
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
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
AnimationTrack.Length:number
Code-Beispiele
Animation für eine bestimmte Dauer abspielen
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
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.Looped:boolean
Code-Beispiele
Animationschleifen
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()
AnimationTrack für eine bestimmte Anzahl von Schleifen abspielen
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("Schleife: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- es ist wichtig, Verbindungen zu trennen, wenn sie nicht mehr benötigt werden
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
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.Priority:Enum.AnimationPriority

Speed
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.Speed:number
Code-Beispiele
Animationsgeschwindigkeit
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("Bei normaler Geschwindigkeit wird die Animation", normalSpeedTime, "Sekunden spielen")
print("Bei 3-facher Geschwindigkeit wird die Animation", fastSpeedTime, "Sekunden spielen")
Animation für eine bestimmte Dauer abspielen
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
Nicht repliziert
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.TimePosition:number
Code-Beispiele
Animation an Position einfrieren
function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Spiele die Animation, wenn sie nicht abgespielt wird
animationTrack:Play()
end
-- Setze die Geschwindigkeit auf 0, um die Animation einzufrieren
animationTrack:AdjustSpeed(0)
-- Springe zur gewünschten TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Spiele die Animation, wenn sie nicht abgespielt wird
animationTrack:Play()
end
-- Setze die Geschwindigkeit auf 0, um die Animation einzufrieren
animationTrack:AdjustSpeed(0)
-- Springe zur gewünschten TimePosition
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
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.WeightCurrent:number
Code-Beispiele
WeightCurrent und WeightTarget
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) -- willkürlich gewählte Wartezeit, damit der Charakter in Position fällt
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("Ziel erreicht")
done = true
end
end

WeightTarget
Schreibgeschützt
Nicht repliziert
Parallel lesen
Funktionen: Animation
Simulationszugang
AnimationTrack.WeightTarget:number
Code-Beispiele
WeightCurrent und WeightTarget
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) -- willkürlich gewählte Wartezeit, damit der Charakter in Position fällt
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("Ziel erreicht")
done = true
end
end

Methoden
AdjustSpeed
Funktionen: Animation
Simulationszugang
AnimationTrack:AdjustSpeed(speed:number):()
Parameter
speed:number
Standardwert: 1
Rückgaben
()
Code-Beispiele
Animation für eine bestimmte Dauer abspielen
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)
Animationsgeschwindigkeit
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("Bei normaler Geschwindigkeit wird die Animation", normalSpeedTime, "Sekunden spielen")
print("Bei 3-facher Geschwindigkeit wird die Animation", fastSpeedTime, "Sekunden spielen")

AdjustWeight
Funktionen: Animation
Simulationszugang
AnimationTrack:AdjustWeight(
weight:number, fadeTime:number
):()
Parameter
weight:number
Standardwert: 1
fadeTime:number
Standardwert: 0.100000001
Rückgaben
()
Code-Beispiele
AnimationTrack Gewicht ändern
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("Zeitdauer zur Änderung des Gewichts " .. 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
Funktionen: Animation
AnimationTrack:GetMarkerReachedSignal(name:string):RBXScriptSignal
Parameter
name:string
Rückgaben
Code-Beispiele
Zuhören von Keyframe-Markern
local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Neue "Animation"-Instanz erstellen
local kickAnimation = Instance.new("Animation")
-- Setze die "AnimationId" auf die entsprechende Animations-Asset-ID
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Animation auf das Humanoid laden
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
-- Spiele Animation-Track ab
kickAnimationTrack:Play()
-- Wenn ein benanntes Ereignis für die Animation definiert wurde, verbinde es mit "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)

GetParameter
Funktionen: Animation
Simulationszugang
AnimationTrack:GetParameter(key:string):Variant
Parameter
key:string
Rückgaben
Variant

GetParameterDefaults
Funktionen: Animation
AnimationTrack:GetParameterDefaults():Dictionary
Rückgaben

GetTargetInstance
Funktionen: Animation
AnimationTrack:GetTargetInstance(name:string):Instance?
Parameter
name:string
Rückgaben

GetTargetNames
Funktionen: Animation
AnimationTrack:GetTargetNames():{any}
Rückgaben

GetTimeOfKeyframe
Funktionen: Animation
AnimationTrack:GetTimeOfKeyframe(keyframeName:string):number
Parameter
keyframeName:string
Rückgaben
Code-Beispiele
Zum Schlüsselbild springen
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
Funktionen: Animation
Simulationszugang
AnimationTrack:Play(
fadeTime:number, weight:number, speed:number
):()
Parameter
fadeTime:number
Standardwert: 0.100000001
weight:number
Standardwert: 1
speed:number
Standardwert: 1
Rückgaben
()
Code-Beispiele
Animation für eine bestimmte Dauer abspielen
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)
Animation an Position einfrieren
function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Spiele die Animation, wenn sie nicht abgespielt wird
animationTrack:Play()
end
-- Setze die Geschwindigkeit auf 0, um die Animation einzufrieren
animationTrack:AdjustSpeed(0)
-- Springe zur gewünschten TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Spiele die Animation, wenn sie nicht abgespielt wird
animationTrack:Play()
end
-- Setze die Geschwindigkeit auf 0, um die Animation einzufrieren
animationTrack:AdjustSpeed(0)
-- Springe zur gewünschten TimePosition
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
Funktionen: Animation
Simulationszugang
AnimationTrack:SetParameter(
key:string, value:Variant
):()
Parameter
key:string
value:Variant
Rückgaben
()

SetTargetInstance
Funktionen: Animation
AnimationTrack:SetTargetInstance(
name:string, target:Instance?
):()
Parameter
name:string
target:Instance?
Rückgaben
()

Stop
Funktionen: Animation
Simulationszugang
AnimationTrack:Stop(fadeTime:number):()
Parameter
fadeTime:number
Standardwert: 0.100000001
Rückgaben
()
Code-Beispiele
AnimationTrack Stop
local function fadeOut(animationTrack, fadeTime)
animationTrack:Stop(fadeTime)
local startTime = tick()
while animationTrack.WeightCurrent > 0 do
task.wait()
end
local timeTaken = tick() - startTime
print("Zeit, die benötigt wurde, um das Gewicht zurückzusetzen: " .. 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)

Events
DidLoop
Funktionen: Animation
AnimationTrack.DidLoop():RBXScriptSignal
Code-Beispiele
AnimationTrack für eine bestimmte Anzahl von Schleifen abspielen
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("Schleife: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- es ist wichtig, Verbindungen zu trennen, wenn sie nicht mehr benötigt werden
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
Funktionen: Animation
AnimationTrack.Ended():RBXScriptSignal
Code-Beispiele
AnimationTrack Beendet
local InsertService = game:GetService("InsertService")
local Players = game:GetService("Players")
-- Erstellen Sie ein NPC-Modell für die Animation.
local npcModel = Players:CreateHumanoidModelFromUserIdAsync(129687796)
npcModel.Name = "JoeNPC"
npcModel.Parent = workspace
npcModel:MoveTo(Vector3.new(0, 15, 4))
local humanoid = npcModel:WaitForChild("Humanoid")
-- Laden Sie eine Animation.
local animationModel = InsertService:LoadAsset(2510238627)
local animation = animationModel:FindFirstChildWhichIsA("Animation", true)
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
-- Verbinden Sie sich mit dem Stopped-Ereignis. Dies wird ausgelöst, wenn die Animation von
-- selbst anhält oder wenn wir explizit Stop aufrufen.
animationTrack.Stopped:Connect(function()
print("Animation gestoppt")
end)
-- Verbinden Sie sich mit dem Ended-Ereignis. Dies wird ausgelöst, wenn die Animation vollständig
-- abgeschlossen ist und die Welt beeinflusst hat. In diesem Fall wird es 3 Sekunden
-- nach dem Aufruf von animationTrack:Stop ausgelöst, da wir ein 3
-- Sekunden-FadeOut übergeben.
animationTrack.Ended:Connect(function()
print("Animation beendet")
animationTrack:Destroy()
end)
-- Führen Sie es aus, lassen Sie ihm etwas Zeit zum Abspielen und stoppen Sie es dann.
print("Play aufrufen")
animationTrack:Play()
task.wait(10)
print("Stop aufrufen")
animationTrack:Stop(3)

KeyframeReached
Veraltet

Stopped
Funktionen: Animation
AnimationTrack.Stopped():RBXScriptSignal
Code-Beispiele
AnimationTrack Gestoppt
local function yieldPlayAnimation(animationTrack, fadeTime, weight, speed)
animationTrack:Play(fadeTime, weight, speed)
animationTrack.Stopped:Wait()
print("Animation wurde gestoppt")
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 Roblox Corporation. Roblox, das Roblox-Logo und "Powering Imagination" gehören zu unseren eingetragenen und nicht eingetragenen Markenzeichen in den USA und anderen Ländern.