銀の弾丸、はじめました

Unityとかガジェットとか

Unityでキャラクターに見つめてもらう

カメラを常に首振りで追尾してもらう.

f:id:japanetfutan:20140824224728p:plain

Head Look Controller

https://www.assetstore.unity3d.com/jp/#!/content/4

このHead Look Testシーンをコピーして使う.

手順

  • Asset -> Import Package -> Charactor Controllerでインポート

  • PlaneにアタッチされたHelp Textを削除してScaleを10, 10, 10くらいにしとく.

  • Human(おっさんモデル)削除

  • Target Sphere(光ってる球)削除

  • CameraControl削除

  • ProjectのStandard Assets Character ControllersのFirst Person ControllerをHierarchyビューにD&D

  • HierarchyのFirst Person Controller -> Main CameraのInspectorにHead Look Controller -> Scripts -> Cursor Hitスクリプトをアタッチ

  • アタッチした項目のHead Lookにモデルを指定

  • Cursor Hitスクリプトを開いてL16〜L20辺りをコメントアウト

カメラの移動処理部分

using UnityEngine;
using System.Collections;

public class CursorHit : MonoBehaviour {
    
    public HeadLookController headLook;
    
    private float offset = 1.5f;
    
    // Update is called once per frame
    void LateUpdate () {
        if (Input.GetKey(KeyCode.UpArrow))
            offset += Time.deltaTime;
        if (Input.GetKey(KeyCode.DownArrow))
            offset -= Time.deltaTime;
        
//      Ray cursorRay = Camera.main.ScreenPointToRay(Input.mousePosition);
//      RaycastHit hit;
//      if (Physics.Raycast(cursorRay, out hit)) {
//          transform.position = hit.point + offset * Vector3.up;
//      }
        
        headLook.target = transform.position;
    }
}
  • ModelにHead Look Controllerスクリプトをアタッチ

  • Modelによって値が変わるが,以下の感じで設定

f:id:japanetfutan:20140824224724p:plain

  • 首,頭
  • 左右の腕の付け根

* Element0だけで,首と頭だけ指定でも機能するかも

  • First Person Controllerの高さやMain Cameraの位置を調整

完成

メモ

  • Modelに軽目の立ちアニメーションを付けておくと自然な感じで良い
  • Modelにアニメーション付けた場合はHead Look ControllerのOverride Animationはオンチェックする
  • 距離や角度でモデルの表情に変化を付けたりすると面白い
  • Oculus Rift対応で例のアレに似た感じのができる
  • 複数のキャラクターでやる場合一工夫必要
  • 目線の追尾を表情Morphとかでできるのかちょっと謎,今後の課題

使用キャラクター:プロ生ちゃん

暮井 慧(プロ生ちゃん)3D モデル Unity パッケージ公開! | プログラミング生放送

プロ生ちゃん,マジ天使!