LoginSignup
3
3

More than 3 years have passed since last update.

[Unity] アニメーションのブレンド

Posted at

アニメーションを同じステート内でブレンドしながら変更する方法です。
複数のアニメーション間を0-1の数値で表現できるのでいろいろと便利です。

_gif_animation_001.gif

まずは新しいステートを作ります。ここではRun_endとしました。
2019-08-21_175030.png

作成したステートを右クリック->Create BlendTree in State を選択します
2019-08-21_180315.jpg

するとMotionのところがBlend Tree になるので、これをダブルクリック
2019-08-21_180633.jpg

+ボタン-Add Motion Field を押してモーションを追加します
2019-08-21_180814.jpg

モーションを追加すると自動的にブレンドパラメーターを設定してくれます。
2019-08-21_181435.gif

アニメーションのブレンドは"Blend"というパラメータを変更することで行います。

animator.SetFloat("Blend", [0f-1f]);

アニメーションのあるオブジェクトに下記を張り付けて
moveSpeedスライダーバーを動かすとモーションが滑らかにブレンドします。

AnimationBrendTreeTest.cs
using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class AnimationBrendTreeTest : MonoBehaviour
{
    [SerializeField,Range(0,1)] float m_moveSpeed=0f;
    Animator m_animator;

    // Start is called before the first frame update
    void Start()
    {
        m_animator = GetComponent<Animator>();
    }

    // Update is called once per frame
    void Update()
    {
        m_animator.SetFloat("Blend", m_moveSpeed);
    }
}

2つ以上のモーションブレンドも可能です
2019-08-21_183148.jpg

gif_animation_004.gif

3
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
3
3