本文へスキップ
Skillpedia
一般的なプログラミング6.6k · #13848

unity-navmesh

できること

ナビゲーションメッシュを使って、Unityのキャラクターが障害物を避けて歩く方法を示します。敵がプレイヤーを追いかけたり、番兵が巡回したりするものを作る開発者向けです。

使う場面

  • ✓Unityで、敵が壁を避けてプレイヤーを追いかけるようにしたいとき。
  • ✓Unityのシーンで、キャラクターが歩けるサーフェスを焼き込む必要があるとき。
  • ✓箱やドアなどの障害物が、プレイ中に経路を遮ったり変えたりすべきとき。

スキルのリンク

https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-navmesh/SKILL.md

コピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。

使い方

いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。

貼り付け用メッセージ

このスキルを使って手伝ってください:https://github.com/gamedev-skills/awesome-gamedev-agent-skills/blob/main/skills/unity/unity-navmesh/SKILL.md このリンクのSKILL.mdファイルを読んで、私の作業でその指示に従ってください。
こういうスキルを、AIが自分で見つけてくれたら?無料のSkillpedia MCPをインストール。1行で、作業の前に15,000+のスキルから探してくれます。1分でインストール →

AIへの頼み方の例

“Unityのレベルの番兵が、壁を避けながらプレイヤーの位置まで歩くようにしてください。”

毎週5つの新しいスキル。1分で読めます。

仕組み

スキルは、ナビゲーションのサーフェスのコンポーネントをレベルに加え、それを焼き込み、エージェントを目的地へ向かわせる方法を説明します。動くものには障害物のコンポーネントを使います。

技術的な内容(元のSKILL.md)

作者による元のテキスト(英語)をGitHubからそのまま表示しています。

Unity NavMesh (AI Navigation)

Give NPCs pathfinding in Unity 6.3 LTS: bake walkable surfaces and move agents around obstacles. Targets Unity 6.3 LTS (6000.3) with the AI Navigation package 2.0 (2.0.16 at last check).

Version trap (Unity 2022+/6): the old built-in Navigation window (Object/Bake tabs, "Navigation Static" flag) is gone. The package's Window → AI → Navigation only holds the Agents and Areas tabs. Baking is now component-based via the AI Navigation package (com.unity.ai.navigation): add a NavMeshSurface to your level geometry and click Bake. The runtime NavMeshAgent/NavMesh API stays in built-in UnityEngine.AI.

When to use

  • Use when an agent needs to walk/chase/patrol to a target, when baking a navigable surface, adding dynamic blockers (NavMeshObstacle), or checking whether a destination is reachable.
  • Use when the project has the AI Navigation package, a NavMeshSurface component, or scripts using UnityEngine.AI.NavMeshAgent.

When not to use: the decision logic of when/where to move (FSMs, behaviour trees, steering) → game-ai (this skill is the Unity movement/pathing mechanism). Force-driven or kinematic movement that isn't pathfinding → unity-physics.

Core workflow

  1. Install the AI Navigation package (Package Manager → com.unity.ai.navigation).
  2. Bake a surface: select the static level geometry, Add Component → Navigation → NavMesh Surface, set the agent type/area settings, and click Bake. Re-bake whenever geometry, NavMeshModifiers, or agent settings change. Agent types (radius, height, step, slope) are defined in Window → AI → Navigation → Agents.
  3. Add a NavMeshAgent to each moving NPC; its radius/height/speed must match the baked agent type, and it must spawn on the baked mesh.
  4. Drive it from script with SetDestination(targetPos); the agent steers and avoids other agents automatically. Detect arrival with remainingDistance/pathPending.
  5. Handle dynamic blockers with NavMeshObstacle (carving) so closed doors/crates block paths without a full re-bake.
  6. Verify with the AI Navigation overlay (the baked mesh is drawn in the Scene view) and by watching agents path around obstacles to the goal; check NavMeshPath.status for unreachable targets.

Patterns

1. Chase/seek with a NavMeshAgent

using UnityEngine;
using UnityEngine.AI;

[RequireComponent(typeof(NavMeshAgent))]
public class Chaser : MonoBehaviour
{
    [SerializeField] private Transform target;
    private NavMeshAgent _agent;

    private void Awake() => _agent = GetComponent<NavMeshAgent>();

    private void Update()
    {
        if (target) _agent.SetDestination(target.position);   // re-path toward the target
    }

    // Arrived? pathPending guards the first frame before a path exists.
    private bool HasArrived() =>
        !_agent.pathPending && _agent.remainingDistance <= _agent.stoppingDistance;
}

2. Check reachability before committing

using UnityEngine.AI;

public bool CanReach(NavMeshAgent agent, Vector3 destination)
{
    var path = new NavMeshPath();
    agent.CalculatePath(destination, path);
    return path.status == NavMeshPathStatus.PathComplete;   // vs Partial / Invalid
}

3. Bake at runtime (for procedurally built or streamed levels)

using Unity.AI.Navigation;   // the package namespace (NavMeshSurface)

[SerializeField] private NavMeshSurface surface;

// After spawning level geometry, build the navmesh in code.
public void RebuildNav() => surface.BuildNavMesh();

4. Dynamic obstacle that carves the mesh

// Add a NavMeshObstacle (Carve = true) to a door/crate. While present it cuts a hole in the
// navmesh so agents route around it; remove/disable it to reopen the path — no re-bake needed.

5. Connect separate mesh pieces with a NavMeshLink (jumps, doors, gaps)

// Two baked surfaces that don't touch (a ledge and the floor below, two platforms across a
// gap) are separate islands — an agent can't path between them. Add Component > Navigation >
// NavMesh Link to bridge them: assign Start/End Transforms, set Width (0 = point-to-point),
// and toggle Bidirectional for one-way vs two-way. NavMeshLink lives in Unity.AI.Navigation.
// It replaces the deprecated built-in OffMeshLink (see pitfalls).

Pitfalls

  • **Looking for the Bake tab or the Naviga
よくある質問

なぜサーフェスを焼き込む必要があるのですか?

焼き込みによって、どの範囲を歩けるかをUnityが把握し、エージェントが行ける場所を知れるからです。

敵がいつ追いかけるかも決めますか?

いいえ。判断のロジックは別のゲームAIのスキルで扱われ、このスキルは移動を扱います。

古いNavigationウィンドウでも動きますか?

スキルは、古いウィンドウはなくなり、焼き込みはAI Navigationパッケージのコンポーネントを使うと注意しています。

詳細

作者による元の説明

Add AI navigation in Unity 6.3 LTS: bake a NavMesh with the AI Navigation package (NavMeshSurface), move agents with NavMeshAgent.SetDestination, and handle dynamic obstacles. Use when setting up pathfinding, making an enemy chase the player, baking navigation, or when the user mentions NavMesh, NavMeshAgent, NavMeshSurface, NavMeshObstacle, or Unity pathfinding.

repo: gamedev-skills/awesome-gamedev-agent-skills

人気

GitHubのスター
6.6k
ランキング
#13848
ライセンス
Apache-2.0
更新日
2026/10/28

このスキルは役に立ちますか?

0

ログイン して投票しましょう。

コメント

  • …

このリポジトリの他のスキル

似ているスキル