學習
引擎類別
Animator

*此內容是使用 AI(Beta 測試版)翻譯,可能含有錯誤。若要以英文檢視此頁面,請按一下這裡



API 參考
屬性
EvaluationThrottled
唯讀
未複製
平行寫入
功能: Animation
Animator.EvaluationThrottled:boolean

PreferLodEnabled
平行讀取
功能: Animation
Animator.PreferLodEnabled:boolean

RootMotion
唯讀
未複製
無法瀏覽
平行寫入
功能: Animation
Animator.RootMotion:CFrame

RootMotionWeight
唯讀
未複製
無法瀏覽
平行寫入
功能: Animation
Animator.RootMotionWeight:number

方法
ApplyJointVelocities
功能: Animation
Animator:ApplyJointVelocities(motors:Variant):()
參數
motors:Variant
返回
()

GetPlayingAnimationTracks
功能: Animation
模擬存取權
Animator:GetPlayingAnimationTracks():{any}
返回

GetTrackByAnimationId
功能: Animation
模擬存取權
Animator:GetTrackByAnimationId(animationId:ContentId):AnimationTrack?
參數
animationId:ContentId
範例程式碼
通過 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()
-- 確保角色的 humanoid 包含 Animator 對象
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- 創建一個新的 Animation 實例並分配動畫資產 ID
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- 將動畫加載到動畫器上
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- 在短暫延遲後播放動畫軌道
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- 通過 ID 獲取軌道並停止播放
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)

LoadAnimation
功能: Animation
模擬存取權
Animator:LoadAnimation(animation:Animation):AnimationTrack
參數
animation:Animation

RegisterEvaluationParallelCallback
功能: Animation
Animator:RegisterEvaluationParallelCallback(callback:function):()
參數
callback:function
返回
()

StepAnimations
外掛程式安全性
功能: Animation
Animator:StepAnimations(deltaTime:number):()
參數
deltaTime:number
返回
()
範例程式碼
在工作室中預覽動畫
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- 找到 AnimationController 和 Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- 載入動畫以創建 AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- 預覽動畫
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- 停止動畫
track:Stop(0)
animator:StepAnimations(0)
-- 重置關節
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)

活動
AnimationPlayed
功能: Animation
Animator.AnimationPlayed(animationTrack:AnimationTrack):RBXScriptSignal
參數
animationTrack:AnimationTrack

©2026 Roblox Corporation、Roblox、Roblox 標誌及 Powering Imagination 是我們在美國及其他國家地區的部分註冊與未註冊商標。