Lớp công cụ
Animator
*Nội dung này được dịch bằng AI (Beta) và có thể có lỗi. Để xem trang này bằng tiếng Anh, hãy nhấp vào đây.
Tóm Tắt
Phương Pháp
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
StepAnimations(deltaTime: number):() |
Sự Kiện
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
Tài Liệu Tham Khảo API
Thuộc Tính
EvaluationThrottled
Mẫu mã
Đánh giá bị giới hạn
local RunService = game:GetService("RunService")
local Workspace = game:GetService("Workspace")
local animationController = Instance.new("AnimationController")
local animator = Instance.new("Animator")
animator.Parent = animationController
animationController.Parent = Workspace
local neck = Instance.new("Motor6D")
local function computeNeckRotation()
return CFrame.Angles(0, 0.01, 0)
end
RunService.PreSimulation:Connect(function()
if not animator.EvaluationThrottled then
neck.Transform = computeNeckRotation() * neck.Transform
end
end)Phương Pháp
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Tham Số
motors:Variant |
Lợi Nhuận
()
GetTrackByAnimationId
Tham Số
animationId:ContentId |
Lợi Nhuận
Mẫu mã
Lấy Đường Dẫn Hoạt Hình theo 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()
-- Đảm bảo rằng nhân vật có một đối tượng Animator trong humanoid
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Tạo một thể hiện Animation mới và gán một ID tài sản hoạt hình
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Tải hoạt hình lên animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Phát đường dẫn hoạt hình sau một khoảng thời gian ngắn
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Lấy đường dẫn theo ID và dừng phát nó
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Tham Số
Lợi Nhuận
StepAnimations
Tham Số
Lợi Nhuận
()
Mẫu mã
Xem trước hoạt ảnh trong Studio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Tìm AnimationController và Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Tải hoạt ảnh để tạo một AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- Xem trước hoạt ảnh
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Dừng hoạt ảnh
track:Stop(0)
animator:StepAnimations(0)
-- Đặt lại các khớp
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)Sự Kiện
AnimationPlayed
Tham Số