Engine-Klasse
Animator
*Dieser Inhalt wurde mit KI (Beta) übersetzt und kann Fehler enthalten. Um diese Seite auf Englisch zu sehen, klicke hier.
Zusammenfassung
Eigenschaften
Methoden
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Events
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
API-Referenz
Eigenschaften
Methoden
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Parameter
motors:Variant |
Rückgaben
()
GetTrackByAnimationId
Parameter
animationId:ContentId |
Rückgaben
Code-Beispiele
Animation-Track nach ID abrufen
local Players = game:GetService("Players")
local RunService = game:GetService("RunService")
local ANIM_ID = "rbxassetid://2515090838"
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- Sicherstellen, dass das Humanoid des Charakters ein Animator-Objekt enthält
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Eine neue Animationsinstanz erstellen und eine Animations-Asset-ID zuweisen
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Die Animation auf den Animator laden
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Den Animationstrack nach einer kurzen Verzögerung abspielen
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Track nach ID abrufen und dessen Abspielung stoppen
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Parameter
Rückgaben
RegisterEvaluationParallelCallback
StepAnimations
Parameter
Rückgaben
()
Code-Beispiele
Animation in Studio Vorschau
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Finde den AnimationController und Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Lade die Animation, um einen AnimationTrack zu erstellen
local track = animationController:LoadAnimation(animation)
track:Play()
-- Vorschau der Animation
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Stoppe die Animation
track:Stop(0)
animator:StepAnimations(0)
-- Setze die Gelenke zurück
for _, descendant in pairs(model:GetDescendants()) do
if descendant:IsA("Motor6D") then
local joint = descendant
joint.CurrentAngle = 0
joint.Transform = CFrame.new()
end
end
end
local character = script.Parent
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
previewAnimation(character, animation)Events
AnimationPlayed
Parameter