アニメーションの使用

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

アニメーションを作成したら、ゲームにそれらを含めるためにスクリプトを使用する必要があります。スクリプトからアニメーションを手動で再生することも、プレイヤーキャラクターのデフォルトアニメーションを置き換えることもできます。

スクリプトからアニメーションを再生する

ユーザーが特定のキーを押すときや特別なアイテムを取得したときなど、スクリプトの内部から直接アニメーションを再生する必要がある場合があります。

ヒューマノイド

Humanoidオブジェクトを含むリグ(典型的なプレイ可能キャラクターなど)でアニメーションを再生するには、次の基本的なパターンに従います。

  1. ローカルプレイヤーのHumanoidAnimatorオブジェクトを含んでいることを確認します。
  2. 正しいAnimationIdを使用して新しいAnimationインスタンスを作成します。
  3. Animator:LoadAnimation()を介してアニメーションをロードしてAnimationTrackを作成します。
  4. AnimationTrack:Play()でトラックを再生します。

例えば、次のLocalScriptStarterPlayerScriptsに配置され、プレイヤーのキャラクターに"キック"アニメーションをロードして再生します。このスクリプトはまた、特定のアニメーションイベントが発生したときに検出するためにGetMarkerReachedSignal()メソッドを使用します。

LocalScript - プレイヤーキャラクターのカスタムアニメーションを再生する

local Players = game:GetService("Players")
local player = Players.LocalPlayer
local character = player.Character or player.CharacterAdded:Wait()
-- キャラクターのヒューマノイドが"Animator"オブジェクトを含んでいることを確認
local humanoid = character:WaitForChild("Humanoid")
local animator = humanoid:WaitForChild("Animator")
-- 新しい"Animation"インスタンスを作成し、アニメーションアセットIDを設定
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- アニメーターにアニメーションをロードする
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- アニメーションのために名前付きイベントが定義されている場合、"GetMarkerReachedSignal()"に接続する
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)
task.wait(4)
-- アニメーショントラックを再生する
kickAnimationTrack:Play()

非ヒューマノイド

Humanoidを含まないリグでアニメーションを再生するには、Animatorを持つAnimationControllerを作成する必要があります。例えば、次のScript(リグの直接の子であることを前提とする)は、"キック"アニメーションをロードして再生します。

Script - キャラクターリグのカスタムアニメーションを再生する

local rig = script.Parent
-- 新しい"Animation"インスタンスを作成し、アニメーションアセットIDを設定
local kickAnimation = Instance.new("Animation")
kickAnimation.AnimationId = "rbxassetid://2515090838"
-- 新しい"AnimationController"と"Animator"を作成
local animationController = Instance.new("AnimationController")
animationController.Parent = rig
local animator = Instance.new("Animator")
animator.Parent = animationController
-- アニメーターにアニメーションをロードする
local kickAnimationTrack = animator:LoadAnimation(kickAnimation)
-- アニメーションのために名前付きイベントが定義されている場合、"GetMarkerReachedSignal()"に接続する
kickAnimationTrack:GetMarkerReachedSignal("KickEnd"):Connect(function(paramString)
print(paramString)
end)
task.wait(4)
-- アニメーショントラックを再生する
kickAnimationTrack:Play()

デフォルトアニメーションを置き換える

デフォルトでは、Robloxプレイヤーキャラクターには走る、登る、泳ぐ、ジャンプするなどの一般的なアニメーションが含まれています。これらのデフォルトアニメーションカタログのアニメーションや独自のカスタムアニメーションと置き換えることができます。

  1. 新しいアニメーションのアセットIDを次の方法で取得します。

  2. Explorerウィンドウで、ServerScriptServiceに新しいScriptを追加します。

    1. ServerScriptServiceにカーソルを合わせ、⊕ボタンをクリックします。
    2. コンテキストメニューからScriptを挿入します。
  3. 新しいスクリプトに次のコードを貼り付けます:

    Script - デフォルトのキャラクターアニメーションを置き換える

    local Players = game:GetService("Players")
    local function onCharacterAdded(character)
    -- ヒューマノイドのアニメーターを取得
    local humanoid = character:WaitForChild("Humanoid")
    local animator = humanoid:WaitForChild("Animator")
    -- すべてのアニメーショントラックを停止
    for _, playingTrack in animator:GetPlayingAnimationTracks() do
    playingTrack:Stop(0)
    end
    local animateScript = character:WaitForChild("Animate")
    --animateScript.run.RunAnim.AnimationId = "rbxassetid://"
    --animateScript.walk.WalkAnim.AnimationId = "rbxassetid://"
    --animateScript.jump.JumpAnim.AnimationId = "rbxassetid://"
    --animateScript.idle.Animation1.AnimationId = "rbxassetid://"
    --animateScript.idle.Animation2.AnimationId = "rbxassetid://"
    --animateScript.fall.FallAnim.AnimationId = "rbxassetid://"
    --animateScript.swim.Swim.AnimationId = "rbxassetid://"
    --animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://"
    --animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://"
    end
    local function onPlayerAdded(player)
    player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
    end
    Players.PlayerAdded:Connect(onPlayerAdded)
  4. デフォルトキャラクターアニメーションを参照している各行のコメントを外し、rbxassetid://の後に置き換えIDを貼り付けます。例えば、デフォルトの走るアニメーションをNinja Runバリアントに変更するには:

    Script - デフォルトのキャラクターアニメーションを置き換える

    local Players = game:GetService("Players")
    local function onCharacterAdded(character)
    -- ヒューマノイドのアニメーターを取得
    local humanoid = character:WaitForChild("Humanoid")
    local animator = humanoid:WaitForChild("Animator")
    -- すべてのアニメーショントラックを停止
    for _, playingTrack in animator:GetPlayingAnimationTracks() do
    playingTrack:Stop(0)
    end
    local animateScript = character:WaitForChild("Animate")
    animateScript.run.RunAnim.AnimationId = "rbxassetid://656118852"
    --animateScript.walk.WalkAnim.AnimationId = "rbxassetid://"
    --animateScript.jump.JumpAnim.AnimationId = "rbxassetid://"
    --animateScript.idle.Animation1.AnimationId = "rbxassetid://"
    --animateScript.idle.Animation2.AnimationId = "rbxassetid://"
    --animateScript.fall.FallAnim.AnimationId = "rbxassetid://"
    --animateScript.swim.Swim.AnimationId = "rbxassetid://"
    --animateScript.swimidle.SwimIdle.AnimationId = "rbxassetid://"
    --animateScript.climb.ClimbAnim.AnimationId = "rbxassetid://"
    end
    local function onPlayerAdded(player)
    player.CharacterAppearanceLoaded:Connect(onCharacterAdded)
    end
    Players.PlayerAdded:Connect(onPlayerAdded)

アニメーションの重みを設定する

同じアクションに対して複数のアニメーションを使用することができます。例えば、デフォルトアニメーションを置き換えるためのコードサンプルには、2つのidleバリエーションがあります。

複数のアニメーションがキャラクターの状態に存在するとき、Animateスクリプトはどちらを再生するかランダムに選択しますが、アニメーションのWeight値を設定することで結果に影響を与えることができます。以下の式に従います:

  • アニメーションの重み / 状態アニメーションのすべての重みの合計

以下の例では、idle.Animation1はキャラクターがアイドル状態のときに⅓の確率で再生され、idle.Animation2は⅔の確率で再生されます。

Script - デフォルトのキャラクターアニメーションを置き換える

animateScript.idle.Animation1.AnimationId = "rbxassetid://656117400"
animateScript.idle.Animation2.AnimationId = "rbxassetid://656118341"
animateScript.idle.Animation1.Weight.Value = 5
animateScript.idle.Animation2.Weight.Value = 10

アニメーション参照

デフォルトキャラクターアニメーション

以下の表には、置き換え可能なすべてのデフォルトキャラクターアニメーションが含まれています。カタログアニメーションや独自のカスタムアニメーションと置き換えることができます。Idleにはプレイ頻度を設定できる2つのバリエーションがあることに注意してください。

キャラクターアクションAnimateスクリプト参照
走るanimateScript.run.RunAnim.AnimationId
歩くanimateScript.walk.WalkAnim.AnimationId
ジャンプanimateScript.jump.JumpAnim.AnimationId
アイドル

animateScript.idle.Animation1.AnimationId
animateScript.idle.Animation2.AnimationId

落下animateScript.fall.FallAnim.AnimationId
泳ぐ

animateScript.swim.Swim.AnimationId

泳ぐ (アイドル)

animateScript.swimidle.SwimIdle.AnimationId

登るanimateScript.climb.ClimbAnim.AnimationId

カタログアニメーション

アバターアニメーションバンドルを使用してデフォルトアニメーションを置き換えるときは、それぞれのアセットIDのために次の参照を使用します。例えば、Ninja Jumpアニメーションを適用したい場合は、656117878を使用します。Idleには複数のバリエーションがあることに注意してください。

宇宙飛行士
走る
891636393
歩く
891636393
ジャンプ
891627522
アイドル
891621366, 891633237, 1047759695
落下
891617961
泳ぐ
891639666
泳ぐ (アイドル)
891663592
登る
891609353
バブル
走る
910025107
歩く
910034870
ジャンプ
910016857
アイドル
910004836, 910009958, 1018536639
落下
910001910
泳ぐ
910028158
泳ぐ (アイドル)
910030921
登る
909997997
カートゥーニー
走る
742638842
歩く
742640026
ジャンプ
742637942
アイドル
742637544, 742638445, 885477856
落下
742637151
泳ぐ
742639220
泳ぐ (アイドル)
742639812
登る
742636889
エルダー
走る
845386501
歩く
845403856
ジャンプ
845398858
アイドル
845397899, 845400520, 901160519
落下
845396048
泳ぐ
845401742
泳ぐ (アイドル)
845403127
登る
845392038
ナイト
走る
657564596
歩く
657552124
ジャンプ
658409194
アイドル
657595757, 657568135, 885499184
落下
657600338
泳ぐ
657560551
泳ぐ (アイドル)
657557095
登る
658360781
浮遊
走る
616010382
歩く
616013216
ジャンプ
616008936
アイドル
616006778, 616008087, 886862142
落下
616005863
泳ぐ
616011509
泳ぐ (アイドル)
616012453
登る
616003713
魔法使い
走る
707861613
歩く
707897309
ジャンプ
707853694
アイドル
707742142, 707855907, 885508740
落下
707829716
泳ぐ
707876443
泳ぐ (アイドル)
707894699
登る
707826056
忍者
走る
656118852
歩く
656121766
ジャンプ
656117878
アイドル
656117400, 656118341, 886742569
落下
656115606
泳ぐ
656119721
泳ぐ (アイドル)
656121397
登る
656114359
海賊
走る
750783738
歩く
750785693
ジャンプ
750782230
アイドル
750781874, 750782770, 885515365
落下
750780242
泳ぐ
750784579
泳ぐ (アイドル)
750785176
登る
750779899
ロボット
走る
616091570
歩く
616095330
ジャンプ
616090535
アイドル
616088211, 616089559, 885531463
落下
616087089
泳ぐ
616092998
泳ぐ (アイドル)
616094091
登る
616086039
Rthro
走る
2510198475
歩く
2510202577
ジャンプ
2510197830
アイドル
2510197257, 2510196951, 3711062489
落下
2510195892
泳ぐ
2510199791
泳ぐ (アイドル)
2510201162
登る
2510192778
スタイリッシュ
走る
616140816
歩く
616146177
ジャンプ
616139451
アイドル
616136790, 616138447, 886888594
落下
616134815
泳ぐ
616143378
泳ぐ (アイドル)
616144772
登る
616133594
スーパーヒーロー
走る
616117076
歩く
616122287
ジャンプ
616115533
アイドル
616111295, 616113536, 885535855
落下
616108001
泳ぐ
616119360
泳ぐ (アイドル)
616120861
登る
616104706
おもちゃ
走る
782842708
歩く
782843345
ジャンプ
782847020
アイドル
782841498, 782845736, 980952228
落下
782846423
泳ぐ
782844582
泳ぐ (アイドル)
782845186
登る
782843869
ヴァンパイア
走る
1083462077
歩く
1083473930
ジャンプ
1083455352
アイドル
1083445855, 1083450166, 1088037547
落下
1083443587
泳ぐ
1083464683
泳ぐ (アイドル)
1083467779
登る
1083439238
ウェアウルフ
走る
1083216690
歩く
1083178339
ジャンプ
1083218792
アイドル
1083195517, 1083214717, 1099492820
落下
1083189019
泳ぐ
1083222527
泳ぐ (アイドル)
1083225406
登る
1083182000
ゾンビ
走る
616163682
歩く
616168032
ジャンプ
616161997
アイドル
616158929, 616160636, 885545458
落下
616157476
泳ぐ
616165109
泳ぐ (アイドル)
616166655
登る
616156119
©2026 Roblox Corporation。Roblox(ロブロックス)、RobloxロゴおよびPowering Imaginationは、米国並びにその他の国における登録商標および非登録商標です。