近づいてきたら逃げる

void OnTriggerStay(Collider other)
{
 Vector3 dir = this.transform.position - other.transform.position;
 Vector3 pos = this.transform.position + dir * 0.5f;
 agent.destination = pos;
}

dirは、thisからotherのベクトル
posにthisがotherから逃げる方向の目的地がセットされる

タグ:

unity
最終更新:2015年04月01日 23:58