Qiita Teams that are logged in
You are not logged in to any team

Log in to Qiita Team
Community
OrganizationAdvent CalendarQiitadon (β)
Service
Qiita JobsQiita ZineQiita Blog
16
Help us understand the problem. What is going on with this article?
@ELIXIR

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

More than 3 years have passed since last update.

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

16
Help us understand the problem. What is going on with this article?
Why not register and get more from Qiita?
  1. We will deliver articles that match you
    By following users and tags, you can catch up information on technical fields that you are interested in as a whole
  2. you can read useful information later efficiently
    By "stocking" the articles you like, you can search right away

Comments

No comments
Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account Login
16
Help us understand the problem. What is going on with this article?