Klasa silnika
Animator
*Ta zawartość została przetłumaczona przy użyciu narzędzi AI (w wersji beta) i może zawierać błędy. Aby wyświetlić tę stronę w języku angielskim, kliknij tutaj.
Podsumowanie
Właściwości
Metody
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Zdarzenia
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
Materiały referencyjne dotyczące interfejsów API
Właściwości
Metody
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Parametry
motors:Variant |
Zwroty
()
GetTrackByAnimationId
Parametry
animationId:ContentId |
Zwroty
Przykłady kodu
Pobierz ścieżkę animacji według ID
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()
-- Upewnij się, że humanoid postaci zawiera obiekt Animator
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Utwórz nową instancję animacji i przypisz ID zasobu animacji
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Załaduj animację na animatora
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Odtwarzaj ścieżkę animacji po krótkim opóźnieniu
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Pobierz ścieżkę według ID i zatrzymaj jej odtwarzanie
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Parametry
Zwroty
RegisterEvaluationParallelCallback
StepAnimations
Parametry
Zwroty
()
Przykłady kodu
Podgląd animacji w Studio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Znajdź AnimationController i Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Załaduj animację, aby utworzyć AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- Podgląd animacji
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Zatrzymaj animację
track:Stop(0)
animator:StepAnimations(0)
-- Zresetuj stawy
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)Zdarzenia
AnimationPlayed
Parametry