Classe de moteur
Animator
*Ce contenu est traduit en utilisant l'IA (Beta) et peut contenir des erreurs. Pour consulter cette page en anglais, clique ici.
Résumé
Propriétés
Méthodes
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Événements
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
Référence API
Propriétés
Méthodes
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Paramètres
motors:Variant |
Retours
()
GetTrackByAnimationId
Paramètres
animationId:ContentId |
Retours
Échantillons de code
Obtenir la piste d'animation par 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()
-- Assurez-vous que le humanoïde du personnage contient un objet Animator
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Créez une nouvelle instance d'Animation et assignez un ID d'actif d'animation
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Chargez l'animation sur l'animateur
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Jouez la piste d'animation après un court délai
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Obtenez la piste par ID et arrêtez sa lecture
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Paramètres
Retours
RegisterEvaluationParallelCallback
StepAnimations
Paramètres
Retours
()
Échantillons de code
Aperçu de l'animation dans Studio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Trouver l'AnimationController et l'Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Charger l'Animation pour créer un AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- Prévisualiser l'animation
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Arrêter l'animation
track:Stop(0)
animator:StepAnimations(0)
-- Réinitialiser les articulations
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)Événements
AnimationPlayed
Paramètres