21
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

アニメーションIKで、(やだ、あの人こっち見てる・・・)にする

Last updated at Posted at 2016-07-12

Mecanimに対応したキャラクターは、アニメーションに「ある点を見る」という行動をブレンドすることが可能です。

まず、Mecanimに対応したキャラクターを用意します。
2016-07-12_215738.png

キャラクターのControllerを選択し、
2016-07-12_220818.png

AnimatorウインドウでBaseLayerのIK PassをOnにします。
2016-07-12_215018.png

用意したキャラクターに、以下のスクリプトをアタッチします。

IKLookAt.cs
using UnityEngine;
using System.Collections;

public class IKLookAt : MonoBehaviour
{
    private Animator avator;
    public Transform lookAtObj = null;

    [SerializeField, Range(0, 1)]
    private float lookAtWeight = 1.0f;
    [SerializeField, Range(0, 1)]
    private float bodyWeight = 0.4f;
    [SerializeField, Range(0, 1)]
    private float headWeight = 0.7f;
    [SerializeField, Range(0, 1)]
    private float eyesWeight = 0.5f;
    [SerializeField, Range(0, 1)]
    private float clampWeight = 0.5f;

    // Use this for initialization
    void Start()
    {
        avator = GetComponent<Animator>();
        if (lookAtObj == null)
        {
            lookAtObj = Camera.main.transform;
        }
    }

    void OnAnimatorIK(int layorIndex)
    {
        if (avator)
        {
            avator.SetLookAtWeight(lookAtWeight, bodyWeight, headWeight, eyesWeight, clampWeight);
            avator.SetLookAtPosition(lookAtObj.position);
        }
    }
}

(やだ、あの人こっち見てる・・・)
2016-07-12_215837.png

目、首、胴の各ブレンド率、ブレンド制限率などはパラメータで変更可能です。
2016-07-12_221058.png

21
18
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
21
18

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?