Clase de motor
Animator
*Este contenido se traduce usando la IA (Beta) y puede contener errores. Para ver esta página en inglés, haz clic en aquí.
Resumen
Propiedades
Métodos
ApplyJointVelocities(motors: Variant):() |
GetTrackByAnimationId(animationId: ContentId):AnimationTrack? |
LoadAnimation(animation: Animation):AnimationTrack |
RegisterEvaluationParallelCallback(callback: function):() |
StepAnimations(deltaTime: number):() |
Eventos
AnimationPlayed(animationTrack: AnimationTrack):RBXScriptSignal |
Referencia API
Propiedades
Métodos
ApplyJointVelocities
Animator:ApplyJointVelocities(motors:Variant):()
Parámetros
motors:Variant |
Devuelve
()
GetTrackByAnimationId
Parámetros
animationId:ContentId |
Devuelve
Muestras de código
Obtener pista de animación por 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()
-- Asegúrate de que el humanoide del personaje contenga un objeto Animator
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- Crea una nueva instancia de Animation y asigna un ID de recurso de animación
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- Carga la animación en el animador
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- Reproduce la pista de animación después de un breve retraso
task.wait(3)
kickAnimationTrack:Play()
local startTime = tick()
RunService:BindToSimulation(function(deltaTime: number)
if tick() - startTime > 1 then
-- Obtén la pista por ID y detén su reproducción
local kickTrack = animator:GetTrackByAnimationId(ANIM_ID)
if kickTrack and kickTrack.IsPlaying then
kickTrack:Stop()
end
end
end)LoadAnimation
Parámetros
Devuelve
RegisterEvaluationParallelCallback
StepAnimations
Parámetros
Devuelve
()
Muestras de código
Vista previa de la animación en el estudio
local RunService = game:GetService("RunService")
local function previewAnimation(model, animation)
-- Encontrar el AnimationController y el Animator
local animationController = model:FindFirstChildOfClass("AnimationController")
local animator = animationController and animationController:FindFirstChildOfClass("Animator")
if not animator then return end
-- Cargar la animación para crear un AnimationTrack
local track = animationController:LoadAnimation(animation)
track:Play()
-- Previsualizar la animación
local startTime = tick()
while (tick() - startTime) < track.Length do
local step = RunService.Heartbeat:wait()
animator:StepAnimations(step)
end
-- Detener la animación
track:Stop(0)
animator:StepAnimations(0)
-- Restablecer las juntas
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)Eventos
AnimationPlayed
Parámetros