AnimationTrack

非推奨を表示

*このコンテンツは、ベータ版のAI(人工知能)を使用して翻訳されており、エラーが含まれている可能性があります。このページを英語で表示するには、 こちら をクリックしてください。

作成できません

Animator 上のアニメーションの再生を制御します。このオブジェクトは作成できません、代わりに Animator:LoadAnimation() メソッドによって返されます。

概要

プロパティ

  • 読み取り専用
    複製されていません
    並列読み取り

    この Animation を作成するために使用されたオブジェクト AnimationTrack

  • 読み取り専用
    複製されていません
    並列読み取り

    AnimationTrack が再生されているときに真を返す読み込み専用プロパティ。

  • 読み取り専用
    複製されていません
    並列読み取り

    AnimationTrack の長さ (秒) を返す読み取り専用プロパティ。アニメーションが完全にロードされるまで 0 が返され、すぐに利用できない可能性があります。

  • 並列読み取り

    アニメーションが終了後に繰り返されるかどうかを設定します。結果を再生している間に変更された場合、アニメーションが終了すると効果が発生します。

  • AnimationTrack の優先順位を設定します。これが設定されている内容に応じて、複数のアニメーションを一度に再生すると、このプロパティを調べて、どの Keyframe Poses が互いに再生されるべきかを判断します。

  • 読み取り専用
    複製されていません
    並列読み取り

    AnimationTrack の速度は、AnimationTrack の現在の再生速度を提供する読み取り専用プロパティです。これにはデフォルト値 1があります。スピードが 1 と同じとき、アニメーションが完了するまでに必要な時間量は AnimationTrack.Length (秒) です。

  • 複製されていません
    並列読み取り

    AnimationTrack がソースアニメーションを再生することで時間内の位置を返します。トラックをアニメーションの特定の瞬間にジャンプさせるように設定できます。

  • 読み取り専用
    複製されていません
    並列読み取り

    AnimationTrack の現在の重量を提供する読み取り専用プロパティ。デフォルト値は 1 です。

  • 読み取り専用
    複製されていません
    並列読み取り

    AnimationTrack の現在の重量を返す読み取り専用プロパティ。

方法

イベント

  • 前のアニメーションループの終了後、次のアップデートで AnimationTrack ループが発生するとき

  • AnimationTrack が完全に世界の何かを移動するのを終えたときに発火します。アニメーションは再生が終わり、「フェードアウト」が終わり、主題は中立なポーズになっています。

  • 再生の度に、AnimationTrack のプレイバックがデフォルトの名前を持っていないKeyframe に到達するたびに発火します - "キーフレーム"。

  • AnimationTrack が再生を終了すると発火します。アニメーショントラックは、アニメーションが "消えて" いる間、対象をアニメーションする可能性があります。アニメーショントラックが世界の何かを完全に移動するのをキャプチャするには、AnimationTrack.Ended イベントを使用します。

プロパティ

Animation

読み取り専用
複製されていません
並列読み取り

この Animation を作成するために使用されたオブジェクト AnimationTrack 。To create an AnimationTrack , you must load an Animation オブジェクト onto an Animator using the Animator:LoadAnimation() メソッド.

コードサンプル

Listen For New Animations

local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
animator.AnimationPlayed:Connect(function(animationTrack)
local animationName = animationTrack.Animation.Name
print("Animation playing " .. animationName)
end)

IsPlaying

読み取り専用
複製されていません
並列読み取り

AnimationTrack が再生されているときに真を返す読み込み専用プロパティ。

このプロパティは、開発者がアニメーションを再生する前に再生しているかどうかをチェックするために使用できます(そうすると再起動します)。開発者がすべての再生を AnimationTracks または Animator または Humanoid に行いたい場合、Animator:GetPlayingAnimationTracks() を使用する必要があります

コードサンプル

AnimationTrack IsPlaying

local function playOrAdjust(animationTrack, fadeTime, weight, speed)
if not animationTrack.IsPlaying then
animationTrack:Play(fadeTime, weight, speed)
else
animationTrack:AdjustSpeed(speed)
animationTrack:AdjustWeight(weight, fadeTime)
end
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playOrAdjust(animationTrack, 1, 0.6, 1)

Length

読み取り専用
複製されていません
並列読み取り

AnimationTrack の長さ (秒) を返す読み取り専用プロパティ。アニメーションが完全にロードされるまで 0 が返され、すぐに利用できない可能性があります。

When the AnimationTrack.Speed of an AnimationTrack が 1 と同じになると、アニメーションは AnimationTrack.Length (秒) で完了します。

コードサンプル

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

Looped

並列読み取り

このプロパティは、アニメーションが終了後繰り返されるかどうかを設定します。結果を再生中に変更された場合、アニメーションが終了した後に効果が生じます。

AnimationTrack のループプロパティは、アニメーションエディタで設定された方法にデフォルトします。しかし、このプロパティは変更でき、ゲームが実行中に AnimationTrack を制御できます。ループは、逆向きで再生されるアニメーション (AnimationTrack.Speed ネガティブ) も正しく処理します。最初のキーフレームに到達すると、最後のキーフレームで再起動します。

このプロパティを使用すると、開発者は Roblox に 2つのバージョンをアップロードする必要なく、同じアニメーションのループバージョンと非ループバージョンを持つことができます。

コードサンプル

Animation Looping

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
local animationTrack = animator:LoadAnimation(animation)
animationTrack.Looped = false
task.wait(3)
animationTrack:Play()
task.wait(4)
animationTrack.Looped = true
animationTrack:Play()
Play AnimationTrack for a Number of Loops

local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("loop: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- it's important to disconnect connections when they are no longer needed
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)
並列読み取り

このプロパティは、AnimationTrack の優先順位を設定します。これが設定されている内容に応じて、複数のアニメーションを一度に再生すると、このプロパティを調べて、どの Keyframe Poses が互いに再生されるべきかを判断します。

優先度プロパティは、AnimationTrack にデフォルトで設定され、Studio のアニメーションエディタ から公開されます。それは Enum.AnimationPriority を使用し、7つの優先レベルを持っています:

  1. アクション4 (最優先)
  2. アクション3
  3. アクション2
  4. 行動
  5. 移動
  6. 待機
  7. コア (最低優先度)

エディタまたはこのプロパティを通じて適切にアニメーションの優先順位を設定すると、複数のアニメーションを衝突させずに再生できます。2つのプレイアニメーションがターゲットに同じ肢を異なる方法で動かすよう指示する場合、最優先の AnimationTrack が表示されます。両方のアニメーションが同じ優先順位を持つ場合、トラックの重量がアニメーションを結合するのに使用されます。

このプロパティはまた、開発者が RobloRoblox(ロブロックス) に追加バージョンをアップロードする必要なく、異なる優先順位で同じアニメーションを再生できるようにします。

Speed

読み取り専用
複製されていません
並列読み取り

AnimationTrack の速度は、AnimationTrack の現在の再生速度を提供する読み取り専用プロパティです。これにはデフォルト値 1があります。スピードが 1 と同じとき、アニメーションが完了するまでに必要な時間量は AnimationTrack.Length (秒) です。

スピードが調整されると、トラックが再生する実際の時間は、長さをスピードで割って計算できます。スピードは単位のない量です。

スピードを使用して、アニメーションの長さを異なるゲームイベント (例えば、能力のリチャージ) にリンクでき、同じアニメーションの異なるバリアントをアップロードする必要はありません。

このプロパティは読み込み専用であり、AnimationTrack:AdjustSpeed() を使用して変更できます。

コードサンプル

Animation Speed

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("At normal speed the animation will play for", normalSpeedTime, "seconds")
print("At 3x speed the animation will play for", fastSpeedTime, "seconds")
Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)

TimePosition

複製されていません
並列読み取り

AnimationTrack がソースアニメーションを再生することで時間内の位置を返します。トラックをアニメーションの特定の瞬間にジャンプさせるように設定できます。

TimePosition は、アニメーションの特定のポイントに移動するように設定できますが、AnimationTrack が再生していなければなりません。また、AnimationTrack:AdjustSpeed() と組み合わせて、アニメーションを指定したポイントで凍結することもできます (速度を 0 に設定する)。

コードサンプル

Freeze Animation at Position

function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

WeightCurrent

読み取り専用
複製されていません
並列読み取り

重量が AnimationTrack に設定されると、すぐに変更されるのではなく、WeightCurrent から AnimationTrack.WeightTarget に移動します。これを行う時間は、アニメーションが再生されたり、重量が調整されたときに渡される fadeTime パラメータによって決まります。

WeightCurrent は、AnimationTrack.WeightTarget に対してチェックして、希望する重量に達したかどうかを確認できます。これらの値は、== 演算子との同等をチェックする必要はありません、これらの値の両方が浮動であるためです。WeightCurrent がターゲット重量に達したかどうかを確認するには、以下のコードサンプルで、それらの値の間の距離が十分に小さいかどうかを確認することをお勧めします (参照してください:下のコードサンプル)。

アニメーション重量システムは、どのように AnimationTracks 同じ優先度で再生されるかを決定するために使用されます。デフォルトの重量は 1 であり、重量ゼロの AnimationTrack では動作が表示されません。任意の時点で表示されるポーズは、すべての Poses および各 AnimationTrack の重み平均によって決定されます。ほとんどの場合、ブレンドアニメーションは必要ありません、そして AnimationTrack.Priority を使用する方が適しています。

コードサンプル

WeightCurrent and WeightTarget

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- arbitrary wait time to allow the character to fall into place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("got there")
done = true
end
end

WeightTarget

読み取り専用
複製されていません
並列読み取り

AnimationTrack.WeightTarget は、AnimationTrack の現在の重量を提供する読み取り専用のプロパティです。デフォルト値は 1 で、AnimationTrack:Play()AnimationTrack:Stop() または AnimationTrack:AdjustWeight() が呼び出されると設定されます。重量が AnimationTrack に設定されると、すぐに変更されるのではなく、WeightCurrent から AnimationTrack.WeightTarget に移動します。これを行う時間は、アニメーションが再生されたり、重量が調整されたときに渡される fadeTime パラメータによって決まります。

WeightCurrent は、AnimationTrack.WeightTarget に対してチェックして、希望する重量に達したかどうかを確認できます。これらの値は、== 演算子との同等をチェックする必要はありません、これらの値の両方が浮動であるためです。WeightCurrent がターゲット重量に達したかどうかを確認するには、以下のコードサンプルで、それらの値の間の距離が十分に小さいかどうかを確認することをお勧めします (参照してください:下のコードサンプル)。

アニメーション重量システムは、どのように AnimationTracks 同じ優先度で再生されるかを決定するために使用されます。デフォルトの重量は 1 であり、重量ゼロの AnimationTrack では動作が表示されません。任意の時点で表示されるポーズは、すべての Poses および各 AnimationTrack の重み平均によって決定されます。ほとんどの場合、ブレンドアニメーションは必要ありません、そして AnimationTrack.Priority を使用する方が適しています。

コードサンプル

WeightCurrent and WeightTarget

local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation1 = Instance.new("Animation")
animation1.AnimationId = "rbxassetid://507770453"
local animation2 = Instance.new("Animation")
animation2.AnimationId = "rbxassetid://507771019"
task.wait(3) -- arbitrary wait time to allow the character to fall into place
local animationTrack1 = animator:LoadAnimation(animation1)
local animationTrack2 = animator:LoadAnimation(animation2)
animationTrack1.Priority = Enum.AnimationPriority.Movement
animationTrack2.Priority = Enum.AnimationPriority.Action
animationTrack1:Play(0.1, 5, 1)
animationTrack2:Play(10, 3, 1)
local done = false
while not done and task.wait(0.1) do
if math.abs(animationTrack2.WeightCurrent - animationTrack2.WeightTarget) < 0.001 then
print("got there")
done = true
end
end

方法

AdjustSpeed

()

この機能はアニメーションの AnimationTrack.Speed を変更します。速度の正の値はアニメーションを前方に再生し、負の値は後方に再生し、0は停止します。

アニメーショントラックの初期速度は、AnimationTrack:Play() でパラメータとして設定されます。しかし、トラックの速度は再生中に調整速度を使用して変更できます。スピードが 1 と同じとき、アニメーションが完了するまでに必要な時間量は AnimationTrack.Length (秒) です。

調整されるとき、トラックが再生する実際の時間は、長さを速度で割って計算できます。速度は単位のない量です。

スピードを使用して、アニメーションの長さを異なるゲームプレイイベント(例えば、能力のリチャージ)にリンクでき、同じアニメーションの異なるバリアントをアップロードする必要はありません。

パラメータ

speed: number

アニメーションが変更される再生速度。

既定値: 1

戻り値

()

コードサンプル

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)
Animation Speed

local ContentProvider = game:GetService("ContentProvider")
local Players = game:GetService("Players")
local localPlayer = Players.LocalPlayer
while not localPlayer.Character do
task.wait()
end
local character = localPlayer.Character
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507770453"
ContentProvider:PreloadAsync({ animation })
local animationTrack = animator:LoadAnimation(animation)
local normalSpeedTime = animationTrack.Length / animationTrack.Speed
animationTrack:AdjustSpeed(3)
local fastSpeedTime = animationTrack.Length / animationTrack.Speed
print("At normal speed the animation will play for", normalSpeedTime, "seconds")
print("At 3x speed the animation will play for", fastSpeedTime, "seconds")

AdjustWeight

()

アニメーションの重量を変更し、オプションの fadeTime パラメータで AnimationTrack.WeightCurrentAnimationTrack.WeightTarget に到達するまでの時間を決定します。

重量が AnimationTrack に設定されると、すぐに変更されるのではなく、WeightCurrent から AnimationTrack.WeightTarget に移動します。これを行う時間は、アニメーションが再生されたり、重量が調整されたときに渡される fadeTime パラメータによって決まります。

WeightCurrent は、AnimationTrack.WeightTarget に対してチェックして、希望する重量に達したかどうかを確認できます。これらの値は、== 演算子との同等をチェックする必要はありません、これらの値の両方が浮動であるためです。WeightCurrent がターゲット重量に達したかどうかを確認するには、以下のコードサンプルで、それらの値の間の距離が十分に小さいかどうかを確認することをお勧めします (参照してください:下のコードサンプル)。

アニメーション重量システムは、どのように AnimationTracks 同じ優先度で再生されるかを決定するために使用されます。デフォルトの重量は 1 であり、重量ゼロの AnimationTrack では動作が表示されません。任意の時点で表示されるポーズは、すべての Poses および各 AnimationTrack の重み平均によって決定されます。以下では、実践でのアニメーションブレンドの例を見てください。ほとんどの場合、ブレンドアニメーションは必要ありません、そして AnimationTrack.Priority を使用する方が適しています。

パラメータ

weight: number

アニメーションが変更される重量。

既定値: 1
fadeTime: number

アニメーションが古い重量と新しい重量の間で消える時間の長さ。

既定値: 0.100000001

戻り値

()

コードサンプル

AnimationTrack Change Weight

local function changeWeight(animationTrack, weight, fadeTime)
animationTrack:AdjustWeight(weight, fadeTime)
local startTime = tick()
while math.abs(animationTrack.WeightCurrent - weight) > 0.001 do
task.wait()
end
print("Time taken to change weight " .. tostring(tick() - startTime))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
changeWeight(animationTrack, 0.6, 1)

GetMarkerReachedSignal

この機能は、event イベントと同様の AnimationTrack.KeyframeReached を返しますが、指定された KeyframeMarkeranimation でヒットしたときにのみ発動します。違いにより、イベントが発射するタイミングをより制御できます。

この機能の使用について詳しくは、 アニメーションイベントアニメーションエディタ 記事で見てください。

参照してください:

パラメータ

name: string

シグナルの名前が作成されているのは、KeyframeMarker ではなく、Keyframe の名前と区別する必要があります。

既定値: ""

戻り値

アニメーションが作成された KeyframeMarker に到達すると作成され、発射されるシグナル。Keyframe の名前と混同しないでください。

コードサンプル

Listening to Keyframe Markers

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.Character:Wait()
local humanoid = character:WaitForChild("Humanoid")
-- Create new "Animation" instance
local kickAnimation = Instance.new("Animation")
-- Set its "AnimationId" to the corresponding animation asset ID
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- Load animation onto the humanoid
local kickAnimationTrack = humanoid:LoadAnimation(kickAnimation)
-- Play animation track
kickAnimationTrack:Play()
-- If a named event was defined for the animation, connect it to "GetMarkerReachedSignal()"
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)

GetTargetInstance

パラメータ

name: string
既定値: ""

戻り値

GetTargetNames


戻り値

GetTimeOfKeyframe

指定された名前の最初の Keyframe の時間位置を AnimationTrack に返します。複数の Keyframes が同じ名前を共有する場合、アニメーションで最も早いものを返します。

この機能は、無効なキーフレーム名 (例えば存在しないもの) で使用したり、基本の Animation がまだロードされていない場合など、エラーを返すことがあります。これを解決するには、正しいキーフレーム名のみが使用され、この関数を呼び出す前にアニメーションがロードされていることを確認してください。

アニメーションがロードされたかどうかを確認するには、AnimationTrack.Length がゼロより大きいかどうかを確認してください。

パラメータ

keyframeName: string

見つかる Keyframe に関連する名前。

既定値: ""

戻り値

時間、秒で、Keyframe は通常の再生速度で発生します。

コードサンプル

Jump To Keyframe

local function jumpToKeyframe(animationTrack, keyframeName)
local timePosition = animationTrack:GetTimeOfKeyframe(keyframeName)
if not animationTrack.IsPlaying then
animationTrack:Play()
end
animationTrack.TimePosition = timePosition
end
local ANIMATION_ID = 0
local KEYFRAME_NAME = "Test"
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://" .. ANIMATION_ID
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
jumpToKeyframe(animationTrack, KEYFRAME_NAME)

Play

()

When AnimationTrack:Play() が呼び出されると、トラックのアニメーションが再生開始し、アニメーションの重量が 0 から指定された重量に増加します (デフォルトは 1) 指定されたフェードタイム (デフォルトは 0.1) にわたって。

AnimationTrack が再生する速度は、速度パラメータ (デフォルトは 1) によって決まります。スピードが 1 と同じになると、トラックが完了するのにかかる秒数は、トラックの AnimationTrack.Length プロパティと同じです。例えば、2の速度は、トラックが2倍の速さで再生するようになります。

アニメーションの重量と速度も、AnimationTrack:AdjustWeight() および AnimationTrack:AdjustSpeed() メソッドを使用してアニメーションが再生開始後に変更できます。

開発者が AnimationTrack.TimePosition を使用して特定のポイントでアニメーションを開始したい場合、これが行われる前にアニメーションが再生されることが重要です。

パラメータ

fadeTime: number

アニメーションの重量が消える時間の長さ。

既定値: 0.100000001
weight: number

アニメーションが再生される重量。

既定値: 1
speed: number

アニメーションの再生速度。

既定値: 1

戻り値

()

コードサンプル

Playing Animation for a Specific Duration

local function playAnimationForDuration(animationTrack, duration)
local speed = animationTrack.Length / duration
animationTrack:Play()
animationTrack:AdjustSpeed(speed)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765000"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playAnimationForDuration(animationTrack, 3)
Freeze Animation at Position

function freezeAnimationAtTime(animationTrack, timePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = timePosition
end
function freezeAnimationAtPercent(animationTrack, percentagePosition)
if not animationTrack.IsPlaying then
-- Play the animation if it is not playing
animationTrack:Play()
end
-- Set the speed to 0 to freeze the animation
animationTrack:AdjustSpeed(0)
-- Jump to the desired TimePosition
animationTrack.TimePosition = (percentagePosition / 100) * animationTrack.Length
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
freezeAnimationAtTime(animationTrack, 0.5)
freezeAnimationAtPercent(animationTrack, 50)

SetTargetInstance

()

パラメータ

name: string
既定値: ""
target: Instance
既定値: ""

戻り値

()

Stop

()

停止する AnimationTrack 。呼び出されると、アニメーションの重量は、オプションの fadeTime パラメータによって指定された期間にわたってゼロに移動します。たとえば、Stop()fadeTime2 で呼び出された場合、トラックの重量がゼロに達して効果が完全に終了わるまでには、2秒かかります。これは、アニメーションの最初の重量にかかわらず、発生することに注意してください。

この効果をオーバーライドして、すぐにアニメーションを終了するために の を使用することは推奨されません。これは、関節がそのプレースに凍結するためです。すぐに終了する必要がある場合は、Motor.MaxVelocityMotor6Ds が十分に高いことを確認してください。彼らが適切にスナップできるように。

パラメータ

fadeTime: number

アニメーションの重量が消える時間、秒単位で。

既定値: 0.100000001

戻り値

()

コードサンプル

AnimationTrack Stop

local function fadeOut(animationTrack, fadeTime)
animationTrack:Stop(fadeTime)
local startTime = tick()
while animationTrack.WeightCurrent > 0 do
task.wait()
end
local timeTaken = tick() - startTime
print("Time taken for weight to reset: " .. tostring(timeTaken))
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
animationTrack:Play()
fadeOut(animationTrack, 1)

イベント

DidLoop

このイベントは、ループされた AnimationTrack がループを完了するたびに、次の更アップデートで発動します。

現在、非ループアニメーショントラックの正確な終わりに発射することもありますが、この動作には頼らないでください。


コードサンプル

Play AnimationTrack for a Number of Loops

local function playForNumberLoops(animationTrack, number)
animationTrack.Looped = true
animationTrack:Play()
local numberOfLoops = 0
local connection = nil
connection = animationTrack.DidLoop:Connect(function()
numberOfLoops = numberOfLoops + 1
print("loop: ", numberOfLoops)
if numberOfLoops >= number then
animationTrack:Stop()
connection:Disconnect() -- it's important to disconnect connections when they are no longer needed
end
end)
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
playForNumberLoops(animationTrack, 5)

Ended

AnimationTrack が完全に世界の何かを移動するのを終えたときに発火します。アニメーションは再生が終わり、「フェードアウト」が終わり、主題は中立なポーズになっています。

これを使用して、アニメーショントラックの主題がAnimationTrackに影響を受けない中立なポーズに戻ったときにアクションを起こすか、AnimationTrackをきれいにすることができます。または関連する接続。


コードサンプル

AnimationTrack Ended

local InsertService = game:GetService("InsertService")
local Players = game:GetService("Players")
-- Create an NPC model to animate.
local npcModel = Players:CreateHumanoidModelFromUserId(129687796)
npcModel.Name = "JoeNPC"
npcModel.Parent = workspace
npcModel:MoveTo(Vector3.new(0, 15, 4))
local humanoid = npcModel:WaitForChild("Humanoid")
-- Load an animation.
local animationModel = InsertService:LoadAsset(2510238627)
local animation = animationModel:FindFirstChildWhichIsA("Animation", true)
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
-- Connect to Stopped event. This fires when animation stops of
-- it's own accord, or we explicitly call Stop.
animationTrack.Stopped:Connect(function()
print("Animation stopped")
end)
-- Connect to Ended event. This fires when when animation is completely
-- finished affecting the world. In this case it will fire 3 seconds
-- after we call animationTrack:Stop because we pass in a 3
-- second fadeOut.
animationTrack.Ended:Connect(function()
print("Animation ended")
animationTrack:Destroy()
end)
-- Run, give it a bit to play, then stop.
print("Calling Play")
animationTrack:Play()
task.wait(10)
print("Calling Stop")
animationTrack:Stop(3)

KeyframeReached

再生の度に、AnimationTrack のプレイバックがデフォルトの名前 - "キーフレーム" を持っていない Keyframe に到達するたびに発火します

このイベントにより、開発者はアニメーションのプリ定義ポイントでコードを実行できます (Keyframe 名によって設定)。これにより、Roblox アニメーションのデフォルト機能が、アニメーションの異なるポイントに Sounds または ParticleEffects を追加することで拡張できます。

Keyframe 名は唯一である必要はありません。たとえば、アニメーションに「パーティクル」と呼ばれる 3つのキーフレームがある場合、KeyframeReached イベントは、これらのキーフレームの1つが達成されるたびに発射します。

Keyframe 名は、アニメーションを作成または編集するときに Roblox アニメーションエディタで設定できます。しかし、それはプレイする前に既存のアニメーションの Script によって設定できません。

パラメータ

keyframeName: string

名前の Keyframe に到達。


Stopped

ファイアは、AnimationTrack が再生を終了するたびに発生します。

このイベントには複数の使用があります。続行する前に、AnimationTrack が停止するまで待つことができます (例えば、連続してアニメーションを再生するようにチェーンする場合)。アニメーション再生中に作成されたすべての Instances をクリーンアップするのにも使用できます。


コードサンプル

AnimationTrack Stopped

local function yieldPlayAnimation(animationTrack, fadeTime, weight, speed)
animationTrack:Play(fadeTime, weight, speed)
animationTrack.Stopped:Wait()
print("Animation has stopped")
end
local animation = Instance.new("Animation")
animation.AnimationId = "rbxassetid://507765644"
local humanoid = script.Parent:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
local animationTrack = animator:LoadAnimation(animation)
yieldPlayAnimation(animationTrack, 1, 0.6, 1)