Animator

顯示已棄用項目

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

負責播放和複製 Animations 的主要類別。所有播放的複製 AnimationTracks 都通過 Animator 實個體、實例處理。

也可以參考 動畫編輯器使用動畫 來學習如何創建和添加預製或自訂動畫到您的遊戲。

概要

屬性

方法

屬性

EvaluationThrottled

唯讀
未複製
無法瀏覽
平行寫入

PreferLodEnabled

平行讀取

RootMotion

唯讀
未複製
無法瀏覽
平行寫入

RootMotionWeight

唯讀
未複製
無法瀏覽
平行寫入

方法

ApplyJointVelocities

()

考慮目前的 遊戲設置和他們目前的遊戲時間和遊戲速度,計算零件之間的相對速度,並將它們應用於 Motor6D.Part1(被認為是"兒童"部分的部分)。這些相對速度計算和分配發生在指定的順序。

此方法不適用於給定的節點,如果節組合的兩個部分目前都是同一裝配的一部分,例如,如果它們仍然直接或間接地通過馬達或焊接連接。

此方法不會為您禁用或移除關節。您必須禁用或其他移除裝配中的剛性聯節,才能呼叫此方法。

提供的 Motor6Ds 不需要是 DataModel 的後裔。在呼叫此方法之前從 DataModel 移除關節是支持的。

參數

motors: Variant
預設值:""

返回

()

GetPlayingAnimationTracks

返回目前播放的列表 AnimationTracks


返回

LoadAnimation

此功能將給定的 Animation 載入到此 Animator ,返回可播放的 AnimationTrack 。當在模型中呼叫 Animator 內的客戶擁有網絡所有權,例如本地玩家的角色或從 BasePart:SetNetworkOwner() ,此功能也會載入服務器的動畫。

請注意,Animator必須在Workspace之前才能呼叫LoadAnimation()或否則將無法恢復AnimationClipProvider服務並發出錯誤。

您應該直接使用此功能,而不是使用類似名稱的 Humanoid:LoadAnimation()AnimationController:LoadAnimation() 功能。這些是這個功能的過時代理,如果沒有存在,也會創建 Animator ;如果不小心,這可能會導致複製問題。

在客戶端或伺服器上載動畫

為了使 AnimationTracks 正確複製,很重要知道何時該在客戶端或伺服器上載它們:

  • 如果 是玩家的 或 的子孫,動畫將從該玩家的客戶端複製到服務器和其他客戶端。

  • 如果 不是玩家角色的後裔,其動畫必須在服務器上載並啟用以重複。

Animator 對象必須初始在伺服器上,並複製到客戶端,才能讓動畫複製功能正常運作。如果在本地創建了 Animator,那麼載入了那個 AnimationTracksAnimator 將不會重複。

參數

animation: Animation

要使用的 Animation

預設值:""

返回

RegisterEvaluationParallelCallback

()

參數

callback: function
預設值:""

返回

()

StepAnimations

()
外掛程式安全性

增加所有載入到 AnimationTrack.TimePosition 上的所有播放 AnimationTracksAnimator 增量,將偏移應用到與 Animator 相關的模型。僅供指令欄或插件使用。

deltaTime 參數決定在動畫進度上增加的秒數。通常這個功能會在迴圈中呼叫以預覽動畫的長度(見例子)。

注意一旦動畫停止播放,模型的關節將需要手動重設到原始位置(見例子)。

此功能用於模擬遊戲未運行時的播放 Animations 。這樣可以讓動畫在沒有執行遊戲的後果的情況下進行預覽,例如執行的腳本。如果函數在遊戲運行時被呼叫,或由 ScriptsLocalScripts 呼叫,將返回錯誤。

設計自己的自訂動畫編輯器的開發人員建議使用此功能來預覽動畫,因為它是官方 Roblox 動畫編輯器插件使用的方法。

參數

deltaTime: number

秒鐘動畫播放的時間量將增加。

預設值:""

返回

()

範例程式碼

This code sample includes a function that can be used to preview an Animation on a Model in Roblox Studio, without needing to run the game. It utilizes the Animator.StepAnimations function, which is the same method the official Roblox Animation Editor uses.

Preview Animation in Studio

local RunService = game:GetService("RunService")
local function studioPreviewAnimation(model, animation)
-- find the AnimationController and Animator
local animationController = model:FindFirstChildOfClass("Humanoid")
or model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animationController or not animator then
return
end
-- load the Animation to create an AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- preview the animation
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- stop the animation
track:Stop(0)
animator:StepAnimations(0)
-- reset the joints
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"
studioPreviewAnimation(character, animation)

活動

AnimationPlayed

對所有 AnimationTrack:Play() 呼叫發射動畫軌道,創建和擁有者是動畫師。

參數

animationTrack: AnimationTrack