Engine-klasse
Animator
*Deze inhoud is vertaald met behulp van AI (bèta) en kan fouten bevatten. Klik hier om deze pagina in het Engels te bekijken.
Samenvatting
Eigenschappen
Methoden
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
StepAnimations(deltaTime: number):() |
Evenementen
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
API-referentie
Eigenschappen
EvaluationThrottled
Codevoorbeelden
Evaluatie Beperkt
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)Methoden
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Parameters
motors:Variant |
Teruggaves
()
GetTrackByAnimationId
Parameters
animationId:ContentId |
Teruggaves
Codevoorbeelden
Krijg Animatie Track op 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()
-- Zorg ervoor dat het humanoid van het personage een Animator object bevat
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Maak een nieuwe Animatie instantie en wijs een animatie asset ID toe
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Laad de animatie op de animator
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Speel de animatie track af na een korte vertraging
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Krijg track op ID en stop de afspelen
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Parameters
Teruggaves
StepAnimations
Parameters
Teruggaves
()
Codevoorbeelden
Voorbeeldanimatie in Studio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Zoek de AnimationController en Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Laad de animatie om een AnimationTrack te creëren
local track = animationController:LoadAnimation(animation)
track:Play()
-- Preview de animatie
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Stop de animatie
track:Stop(0)
animator:StepAnimations(0)
-- Reset de gewrichten
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)Evenementen
AnimationPlayed
Parameters