负责播放和复制 Animations 的主要类别。所有播放的复制 AnimationTracks 都通过 Animator 实例进行处理。
概要
属性
方法
计算零件之间的相对速度,并将其应用到 Motor6D.Part1 。这些相对速度计算和分配发生在提供的顺序。
返回正在播放的列表 AnimationTracks .
将 Animation 加载到 Animator 上,返回一个 AnimationTrack 。
增加所有加载到 AnimationTrack.TimePosition 上的所有播放 AnimationTracks 的 Animator 值,将抵消应用到与 Animator 相关的模型。仅供命令栏或插件使用。
活动
当动画师开始播放动画时触发。
属性
方法
ApplyJointVelocities
考虑到当前的 游戏集和他们当前的游戏时间和速度,计算部件之间的相对速度,并将其应用于 Motor6D.Part1 (被认为是“孩子”部分的部件)。这些相对速度计算和分配发生在提供的顺序。
该方法不适用于给定的关节的速度,如果关接头的两个部分当前仍然由电机或焊接直接或间接连接,例如,如果它们仍然由电机或焊接连接在一起。
该方法不会为您禁用或移除关节。您必须禁用或其他方式移除装配中的刚性节点,才能调用此方法。
给定的 Motor6Ds 不需要是 DataModel 的后裔。在调用此方法之前从 DataModel 中移除关节是支持的。
参数
返回
LoadAnimation
此函数将给定的 Animation 加载到这个 Animator 上,返回可播放的 AnimationTrack 。当在模型中调用 Animator 内的客户端拥有网络所有权时,例如本地玩家的角色或来自 BasePart:SetNetworkOwner() ,此函数还会加载服务器的动画。
请注意,Animator 必须在 Workspace 之前才能调用LoadAnimation() 或否则将无法检索AnimationClipProvider 服务并发出错误。
您应该直接使用此函数,而不是使用类似名称的 Humanoid:LoadAnimation() 和 AnimationController:LoadAnimation() 函数。这些是此函数的过时代理,如果没有存在,也会创建一个 Animator ;如果你不小心,这可能会导致复制问题。
在客户端或服务器上加载动画
为了使 AnimationTracks 正确复制,重要的是要知道它们何时应该加载到客户端或服务器上:
如果 是玩家的 或 的后裔,动画将从该玩家的客户端复制到服务器和其他客户端。
如果 不是玩家角色的子孙,其动画必须在服务器上加载并启动以进行复制,否则无法复制。
服务器上必须初始创建 Animator 对象,并复制到客户端,才能实现动画复制。如果在本地创建了 Animator ,那么 AnimationTracks 加载了那个 Animator 将不会复制。
参数
返回
StepAnimations
增加所有加载到 AnimationTrack.TimePosition 上的所有播放 AnimationTracks 的 Animator 值,将抵消应用到与 Animator 相关的模型。仅供命令栏或插件使用。
deltaTime 参数决定在动画进度上增加的秒数。通常,此函数将在循环中调用以预览动画的长度(见示例)。
请注意,一旦动画停止播放,模型的关节需要手动重置到原始位置(见示例)。
这个函数用于模拟游戏不运行时的播放 Animations 。这允许动画在没有运行游戏的后果的情况下进行预览,例如脚本执行。如果函数在游戏运行时被调用,或由 Scripts 或 LocalScripts 调用,它将返回错误。
开发人员设计自己的自定义动画编辑器时,建议使用此函数预览动画,因为它是官方 Roblox 动画编辑器插件使用的方法。
参数
秒数动画播放的时间量要增加。
返回
代码示例
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.
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)