Engine Class
Animator
*เนื้อหานี้แปลโดยใช้ AI (เวอร์ชัน Beta) และอาจมีข้อผิดพลาด หากต้องการดูหน้านี้เป็นภาษาอังกฤษ ให้คลิกที่นี่
สรุป
คุณสมบัติ
วิธีการ
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
เหตุการณ์
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
เอกสารอ้างอิงเกี่ยวกับ API
คุณสมบัติ
วิธีการ
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
พารามิเตอร์
motors:Variant |
ส่งค่ากลับ
()
GetTrackByAnimationId
พารามิเตอร์
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()
-- ตรวจสอบให้แน่ใจว่ามนุษย์ของตัวละครมีวัตถุ Animator
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- สร้างอินสแตนซ์ Animation ใหม่และกำหนด ID แอสเซ็ตอนิเมชัน
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- โหลดอนิเมชันลงบน Animator
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
พารามิเตอร์
ส่งค่ากลับ
RegisterEvaluationParallelCallback
StepAnimations
พารามิเตอร์
ส่งค่ากลับ
()
ตัวอย่างโค้ด
ตัวอย่างการแสดงอนิเมชันใน Studio
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
-- โหลด Animation เพื่อสร้าง 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
พารามิเตอร์