エンジンクラス
Animator
*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。
概要
方法
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()
-- キャラクターのヒューマノイドにアニメーターオブジェクトが含まれていることを確認する
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- 新しいAnimationインスタンスを作成し、アニメーションアセットIDを割り当てる
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = ANIM_ID
-- アニメーターにアニメーションを読み込む
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
パラメータ
戻り値
()
コードサンプル
スタジオでのアニメーションのプレビュー
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
パラメータ