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
Thuộc Tính
Phương Pháp
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Sự Kiện
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
Tài Liệu Tham Khảo API
Thuộc Tính
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 Animation Track 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 humanoid của nhân vật chứa một đối tượng Animator
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Tạo một instance Animation mới và gán một ID tài sản hoạt ảnh
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Tải hoạt ảnh lên animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Phát animation track 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 track 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
RegisterEvaluationParallelCallback
StepAnimations
Tham Số
Lợi Nhuận
()
Mẫu mã
Xem trước hoạt hì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 ra 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ố