• Nav Mesh設定

  • Nav Mesh設定

■AIの経路を事前計算する
http://tsubakit1.hateblo.jp/entry/2014/09/28/233000

・ステージを作る(Box ColliderとかMesh Collider入り)
・地形となるGameObjectをstatic属性に変更
親オブジェクトをStaticにすると子供もStaticになる

・NavMeshの設定
Window>NavigationでNavmeshウィンドウ→Object→Bake(そしてRadiusで調整)

■マップから落ちないようにステージ上を歩かせる楽な方法
http://tsubakit1.hateblo.jp/entry/20131104/1383573538

・動かしたいオブジェクトにNac Mesh Agentコンポーネントを追加する

★ポイント★Targetの位置に向かって自動的に動く
public var target : Transform;
var agent : NavMeshAgent;
function Start () {
    agent = GetComponent(NavMeshAgent);
    target.position = Vector3(0,0.6,-8);
}
function Update () {
    GetComponent(Animator).SetFloat("Speed", agent.velocity.sqrMagnitude);//速度-アニメ連動
    agent.SetDestination(target.position);
}

移動するだけならこれだけでOK

■NavmeshのAI経路探索とAnimatorのアニメーションを連動させる #Unity
http://tsubakit1.hateblo.jp/entry/2015/07/02/233000

・オブジェクトについてるAnimator→Apply Root Motionのチェックを外す
・Parametersに切替える要素(Speedとか)を作成(数値は5.0で)
・AnimatorでCreate State>From New Blend Treeを作る
・Blend Treeをダブルクリック★して中身を覗く
・Motion→[+]→Add Motion Fieldでモーション追加(x3)
・IDLE,WAL,RUNのモーションを登録
・Automate thresholdsのチェックを外す
・モーションの閾値登録(0;0.3;5)
・Parameterを指定(Speed)
・AnimationConrollerにBlend Treeを登録

終了距離が近づいてきたら、動かないアニメーションに切り替える

・AnimatorにBoolのIsStopを作る
・Blend TreeからIDLEにつなげる(IsStop が true)
GetComponent(Animator).SetBool("IsStop", agent.remainingDistance < agent.stoppingDistance);

・StoppingDistanceはNav Mesh Agentで設定可能(初期値0なので1とかにする)








 

 

 

 

最終更新:2016年08月15日 14:10