
ナビメッシュエージェントが目的地に向かう時に小刻みにワープさせてみました。
まず、目的地を設定した後に、前の記事の方法で経路上の位置を等間隔に取得します。オレンジ色の球を置いたときにVector3のリストに球の位置を追加していって、最後に目的地の位置も入れます。
そして、3秒ごとにリストのはじめから順にワープさせていって、目的地に着いたら、移動とアニメーションを停止します。
second += Time.deltaTime;
if (second >= 3f)
{
second = 0f;
if (n < points.Count)
{
pos = points[n];
agent.Warp(pos); // ワープさせる
agent.path = path; // パスを再設定
if (n == points.Count - 1)
{
animator.SetBool("Stay", true); // 立ち止まる
agent.isStopped = true;
}
n++;
}
else {
}
}

停止するときは、走っているステートから立ち止まっているステートに遷移させますが、遷移のTransition Durationを0にするとピタッと止まりました。

