[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6KR6D7V5DVSAKJW2RDBK0X2":3,"skill-same:01M6KR6D7V5DVSAKJW2RDBK0X2":83},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":29,"linkOnly":30,"markdownContent":31,"markdownBody":32,"frontMatter":33,"refName":34,"commitSha":35,"skillDirectory":36,"forksCount":37,"repositoryHtmlUrl":38,"repositoryHomepageUrl":6,"ownerHtmlUrl":39,"ownerBlogUrl":40,"ownerDescription":41,"updatedAt":42,"install":43,"resources":56},"01M6KR6D7V5DVSAKJW2RDBK0X2","ai-navigation",null,"Use when implementing AI movement — NavigationAgent2D\u002F3D, steering behaviors, behavior trees, and patrol patterns","jame581\u002FGodotPrompter","jame581","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F21112138?v=4","01M6KR3KEQ9Z30WVJRR2E2ZVXE","Jan Mesarč","01M6KR3KJVRMPDSMASQPBCBVK3",964,"MIT","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28],"navigation","ai navigation","3D","behavior","use","patrol","patterns","trees","implementing","when","2026-11-10 10:12:30",false,"---\nname: ai-navigation\ndescription: Use when implementing AI movement — NavigationAgent2D\u002F3D, steering behaviors, behavior trees, and patrol patterns\n---\n\n# AI Navigation in Godot 4.3+\n\nCover NavigationAgent2D\u002F3D, steering behaviors, behavior trees, and patrol patterns. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **state-machine** for AI state management, **component-system** for modular AI behaviors, **player-controller** for movement physics patterns, **math-essentials** for pathfinding vectors and steering math, **limboai** for BT + HSM with a visual editor, **beehave** for lightweight GDScript behavior trees. For a structured behavior tree (rather than steering\u002Fnavigation), see the comparison tables in **limboai** and **beehave**.\n\n---\n\n## 1. Navigation Setup\n\n### Scene Structure\n\n```\nWorld (Node2D or Node3D)\n└── NavigationRegion2D (or NavigationRegion3D)\n    ├── TileMapLayer \u002F StaticBody2D (geometry)\n    └── Enemy (CharacterBody2D with NavigationAgent2D child)\n```\n\n### NavigationRegion2D \u002F NavigationRegion3D\n\n1. Add a **NavigationRegion2D** (or **NavigationRegion3D**) node to your scene.\n2. Assign a **NavigationPolygon** (2D) or **NavigationMesh** (3D) resource to it.\n3. Draw the walkable area in the NavigationPolygon editor, or configure the NavigationMesh bounds in 3D.\n4. **Bake the mesh at edit time:** select the NavigationRegion node → click **Bake NavigationPolygon** (2D) or **Bake NavigationMesh** (3D) in the toolbar.\n5. **Bake at runtime** when the world changes dynamically:\n\n```gdscript\n# 2D\n$NavigationRegion2D.bake_navigation_polygon()\n\n# 3D\n$NavigationRegion3D.bake_navigation_mesh()\n```\n\n```csharp\n\u002F\u002F 2D\nGetNode\u003CNavigationRegion2D>(\"NavigationRegion2D\").BakeNavigationPolygon();\n\n\u002F\u002F 3D\nGetNode\u003CNavigationRegion3D>(\"NavigationRegion3D\").BakeNavigationMesh();\n```\n\n### Async Navigation Baking\n\nNavigation baking can cause frame drops on large maps, so regions bake on a background thread by default: `bake_navigation_polygon()` (2D) and `bake_navigation_mesh()` (3D) take `on_thread = true` unless you pass `false`. Connect the region's `bake_finished` signal (use `CONNECT_ONE_SHOT`) to know when the mesh is ready. Threaded baking is unavailable on Web builds without thread support.\n\n> See [references\u002Fasync-baking.md](references\u002Fasync-baking.md) for the full GDScript and C# background-thread bake examples (2D and 3D).\n\n> **When to use async baking:** Procedurally generated levels, destructible terrain, or any scene where the navigation mesh must be rebuilt at runtime. The game continues running while the mesh bakes.\n\n### Navigation Layers\n\nNavigation layers let you separate walkable areas for different agent types (ground troops, flying units, large enemies).\n\n```gdscript\n# Assign layer bits on the NavigationRegion (Inspector or code)\n# Layer 1 = ground, Layer 2 = air, Layer 3 = large\n\n# On the NavigationAgent, set matching layers:\n$NavigationAgent2D.navigation_layers = 1   # ground only\n$NavigationAgent2D.navigation_layers = 2   # air only\n$NavigationAgent2D.navigation_layers = 1 | 2  # both (bitwise OR)\n```\n\n```csharp\n\u002F\u002F Assign layer bits on the NavigationRegion (Inspector or code)\n\u002F\u002F Layer 1 = ground, Layer 2 = air, Layer 3 = large\n\nvar navAgent = GetNode\u003CNavigationAgent2D>(\"NavigationAgent2D\");\nnavAgent.NavigationLayers = 1;       \u002F\u002F ground only\nnavAgent.NavigationLayers = 2;       \u002F\u002F air only\nnavAgent.NavigationLayers = 1 | 2;   \u002F\u002F both (bitwise OR)\n```\n\n> Set `navigation_layers` on both the **NavigationRegion** and the **NavigationAgent** so they match. Mismatched layers are one of the most common reasons an agent finds no path.\n\n---\n\n## 2. NavigationAgent2D Basic Usage\n\n### GDScript\n\n```gdscript\nextends CharacterBody2D\n\n@export var speed: float = 120.0\n\n@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D\n\n\nfunc _ready() -> void:\n\t# velocity_computed fires when avoidance calculates a safe velocity\n\tnav_agent.velocity_computed.connect(_on_velocity_computed)\n\n\nfunc _physics_process(delta: float) -> void:\n\tif nav_agent.is_navigation_finished():\n\t\treturn\n\n\tvar next_pos: Vector2 = nav_agent.get_next_path_position()\n\tvar direction: Vector2 = (next_pos - global_position).normalized()\n\tvar desired_velocity: Vector2 = direction * speed\n\n\tif nav_agent.avoidance_enabled:\n\t\t# Hand desired velocity to the avoidance system; wait for the signal\n\t\tnav_agent.velocity = desired_velocity\n\telse:\n\t\tvelocity = desired_velocity\n\t\tmove_and_slide()\n\n\nfunc _on_velocity_computed(safe_velocity: Vector2) -> void:\n\tvelocity = safe_velocity\n\tmove_and_slide()\n\n\nfunc set_target(target_pos: Vector2) -> void:\n\tnav_agent.target_position = target_pos\n```\n\n**Key NavigationAgent2D properties:**\n\n| Property | Purpose |\n|---|---|\n| `target_position` | World-space destination |\n| `path_desired_distance` | How close to each waypoint counts as reached (default 20) |\n| `target_desired_distance` | How close to the final target counts as finished (default 10) |\n| `avoidance_enabled` | Enable RVO obstacle avoidance |\n| `radius` | Agent collision radius for avoidance |\n| `time_horizon_agents` | Seconds of avoidance look-ahead (tune to reduce jitter) |\n\n### C#\n\n```csharp\nusing Godot;\n\npublic partial class Enemy2D : CharacterBody2D\n{\n    [Export] public float Speed { get; set; } = 120f;\n\n    private NavigationAgent2D _navAgent;\n\n    public override void _Ready()\n    {\n        _navAgent = GetNode\u003CNavigationAgent2D>(\"NavigationAgent2D\");\n        _navAgent.VelocityComputed += OnVelocityComputed;\n    }\n\n    public override void _PhysicsProcess(double delta)\n    {\n        if (_navAgent.IsNavigationFinished()) return;\n\n        Vector2 nextPos = _navAgent.GetNextPathPosition();\n        Vector2 direction = (nextPos - GlobalPosition).Normalized();\n        Vector2 desiredVelocity = direction * Speed;\n\n        if (_navAgent.AvoidanceEnabled)\n            _navAgent.Velocity = desiredVelocity;\n        else\n        {\n            Velocity = desiredVelocity;\n            MoveAndSlide();\n        }\n    }\n\n    private void OnVelocityComputed(Vector2 safeVelocity)\n    {\n        Velocity = safeVelocity;\n        MoveAndSlide();\n    }\n\n    public void SetTarget(Vector2 targetPos) => _navAgent.TargetPosition = targetPos;\n}\n```\n\n---\n\n## 3. NavigationAgent3D Basic Usage\n\nA `CharacterBody3D` drives a `NavigationAgent3D` by calling `get_next_path_position()` each physics frame, flattening the direction on Y, and keeping gravity separate. With `avoidance_enabled` the desired velocity goes to `nav_agent.velocity` and movement happens in the `velocity_computed` handler; otherwise `move_and_slide()` is called directly. Targets are set through `target_position` and completion is checked with `is_navigation_finished()`.\n\n> See [references\u002Fnavigation-agent-3d.md](references\u002Fnavigation-agent-3d.md) for the full GDScript and C# `NavigationAgent3D` enemy example.\n\n---\n\n## 4. Steering Behaviors\n\nLightweight per-frame calculations (seek, flee, arrive, wander) that produce natural-looking movement without a navigation mesh. Combine them by summing the returned vectors, or pick one and assign it to `velocity` each `_physics_process` tick.\n\n> See [references\u002Fsteering-behaviors.md](references\u002Fsteering-behaviors.md) for the full GDScript and C# implementations of seek, flee, arrive (with deceleration ramp), and wander (with circle-projection jitter).\n\n---\n\n## 5. Patrol Patterns\n\nA `NavigationAgent2D` plus an array of `Marker2D` waypoints and a `Timer` for the pause at each point produces a clean patrol loop. Cycle the index on `wait_timer.timeout`, set `nav_agent.target_position` to the next waypoint, and gate movement on `is_navigation_finished()`.\n\n> See [references\u002Fpatrol-patterns.md](references\u002Fpatrol-patterns.md) for the full GDScript and C# waypoint-chain patrol with wait-timer pauses.\n\n---\n\n## 6. Behavior Tree Concept\n\nA behavior tree (BT) is a tree of nodes evaluated every tick. Three core node types:\n\n| Type | Succeeds when | Fails when |\n|---|---|---|\n| **Sequence** | all children succeed (AND) | any child fails |\n| **Selector** | any child succeeds (OR) | all children fail |\n| **Action** | the leaf action completes | the leaf reports failure |\n\nSequences model \"do A then B then C\". Selectors model \"try A, else try B, else try C\".\n\n> See [references\u002Fbehavior-trees.md](references\u002Fbehavior-trees.md) for the full lightweight BT implementation (BTNode base + Sequence \u002F Selector \u002F Action) and a worked enemy that uses \"chase OR patrol\", in both GDScript and C#.\n\n---\n\n## 7. Chase + Attack Pattern\n\nCombines NavigationAgent2D with a state machine. See the **state-machine** skill for the full FSM infrastructure.\n\n### States\n\n| State | Entry condition | Exit condition |\n|---|---|---|\n| PATROL | default \u002F player escaped | player enters detect_range |\n| CHASE | player in detect_range | player in attack_range OR player escaped |\n| ATTACK | player in attack_range | player left attack_range |\n\n> See [references\u002Fchase-attack.md](references\u002Fchase-attack.md) for the full GDScript and C# implementation (PATROL → CHASE → ATTACK transitions, attack cooldown timer, patrol-waypoint advancement, escape-range hand-off back to patrol).\n\n> For larger projects, extract each state into its own node class using the **state-machine** skill and inject the `NavigationAgent2D` reference from the parent.\n\n---\n\n## 8. Dedicated 2D Navigation Server (Godot 4.5+)\n\nPrior to Godot 4.5, `NavigationServer2D` was a thin frontend that delegated all work to the 3D navigation server internally. Godot 4.5 splits them into fully independent servers. The change is **transparent** — no API changes and no code migration is required — but it brings two practical benefits:\n\n- **Independence:** 2D navigation no longer runs through the 3D server — 2D maps, regions and agents are handled by their own implementation.\n- **Smaller exports for 2D-only games:** custom export templates can be compiled without the 3D navigation server (`disable_navigation_3d=yes`), reducing binary size.\n\n```gdscript\n# No code change needed — NavigationServer2D calls work identically.\n# The split is internal; you continue using NavigationServer2D as before.\n\n# Example: query a path directly via the server (unchanged API).\n# Not named get_path_to: that is Node.get_path_to(node) and cannot be overridden with another signature.\nfunc find_path_to(target: Vector2) -> PackedVector2Array:\n    var map: RID = get_world_2d().get_navigation_map()\n    return NavigationServer2D.map_get_path(\n        map,\n        global_position,\n        target,\n        true  # optimize path\n    )\n```\n\n```csharp\n\u002F\u002F No code change needed — NavigationServer2D calls work identically.\npublic Vector2[] FindPathTo(Vector2 target)\n{\n    Rid map = GetWorld2D().NavigationMap;\n    return NavigationServer2D.MapGetPath(map, GlobalPosition, target, true);\n}\n```\n\n> **2D-only projects:** Stock export templates still include 3D navigation. To drop it, compile custom export templates with the `disable_navigation_3d=yes` SCons option (Godot 4.5+). This is only safe if no 3D navigation nodes (`NavigationRegion3D`, `NavigationAgent3D`) are used anywhere in the project.\n\n---\n\n## 9. Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---|---|---|\n| **Navigation mesh not baked** | Agent stands still; no path found | Bake the NavigationPolygon\u002FNavigationMesh before running, or call `bake_navigation_polygon()` at runtime after scene loads |\n| **`agent_radius` too large** | Agent can't fit through doorways or narrow corridors | Lower `agent_radius` on the NavigationPolygon\u002FNavigationMesh and rebake — the agent's own `radius` is for avoidance only and does not affect pathfinding |\n| **Avoidance jitter** | Agent stutters or oscillates when near other agents | Increase `time_horizon_agents` (try 2–4 s) or slightly lower `max_speed` on the agent |\n| **Path recalculation too frequent** | CPU spike each frame; agents lag | Add a `Timer` (0.2–0.5 s) and only set `target_position` when the timer fires, not every physics frame |\n| **Wrong navigation layer** | Agent ignores some regions or finds no path | Confirm `navigation_layers` bitmask matches between the NavigationRegion and the NavigationAgent |\n| **Target set before NavigationServer is ready** | Path is empty on the first frame | The map first synchronizes on a physics frame — in `_ready()`, `await get_tree().physics_frame` (or `NavigationServer2D.map_changed`) before setting `target_position` |\n| **Gravity ignored in 3D** | Agent floats or sinks into the floor | Always accumulate `velocity.y` from gravity separately; only zero out X\u002FZ from the nav direction |\n| **Baking causes frame drop** | Bake forced onto the main thread (`on_thread = false`), or parsing a very large scene | Keep the default threaded bake (`bake_navigation_mesh()`); connect `bake_finished` and never block waiting for it |\n\n> ⚠️ **Changed in Godot 4.7:** `NavigationServer3D.map_get_closest_point_normal(map, to_point)` now returns a normalized vector ([GH-119022](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119022)) — previously the returned surface normal could be unnormalized. Code that compensated by calling `normalized()` on the result keeps working; code that relied on the unnormalized magnitude breaks.\n\n---\n\n## 10. Checklist\n\n- [ ] NavigationRegion2D\u002F3D added to the scene with a NavigationPolygon\u002FNavigationMesh resource\n- [ ] Navigation mesh baked (edit-time or at runtime before the agent needs a path)\n- [ ] `navigation_layers` bitmask matches between NavigationRegion and NavigationAgent\n- [ ] `NavigationAgent2D`\u002F`NavigationAgent3D` is a **child** of the enemy node\n- [ ] `get_next_path_position()` called each physics frame, not `get_target_position()`\n- [ ] `velocity_computed` signal connected when `avoidance_enabled` is `true`\n- [ ] `is_navigation_finished()` checked before moving to avoid jitter at the destination\n- [ ] Path target updated via a throttle timer rather than every frame when following a moving player\n- [ ] `agent_radius` small enough to fit through the narrowest passage in the level\n- [ ] Gravity applied independently of horizontal nav velocity (3D only)\n- [ ] Large or dynamic maps keep the default threaded bake (`bake_navigation_mesh()`, `on_thread = true`) and wait for `bake_finished`\n- [ ] 2D-only projects on Godot 4.5+ can build custom export templates with `disable_navigation_3d=yes` to reduce export size\n","# AI Navigation in Godot 4.3+\n\nCover NavigationAgent2D\u002F3D, steering behaviors, behavior trees, and patrol patterns. All examples target Godot 4.3+ with no deprecated APIs.\n\n> **Related skills:** **state-machine** for AI state management, **component-system** for modular AI behaviors, **player-controller** for movement physics patterns, **math-essentials** for pathfinding vectors and steering math, **limboai** for BT + HSM with a visual editor, **beehave** for lightweight GDScript behavior trees. For a structured behavior tree (rather than steering\u002Fnavigation), see the comparison tables in **limboai** and **beehave**.\n\n---\n\n## 1. Navigation Setup\n\n### Scene Structure\n\n```\nWorld (Node2D or Node3D)\n└── NavigationRegion2D (or NavigationRegion3D)\n    ├── TileMapLayer \u002F StaticBody2D (geometry)\n    └── Enemy (CharacterBody2D with NavigationAgent2D child)\n```\n\n### NavigationRegion2D \u002F NavigationRegion3D\n\n1. Add a **NavigationRegion2D** (or **NavigationRegion3D**) node to your scene.\n2. Assign a **NavigationPolygon** (2D) or **NavigationMesh** (3D) resource to it.\n3. Draw the walkable area in the NavigationPolygon editor, or configure the NavigationMesh bounds in 3D.\n4. **Bake the mesh at edit time:** select the NavigationRegion node → click **Bake NavigationPolygon** (2D) or **Bake NavigationMesh** (3D) in the toolbar.\n5. **Bake at runtime** when the world changes dynamically:\n\n```gdscript\n# 2D\n$NavigationRegion2D.bake_navigation_polygon()\n\n# 3D\n$NavigationRegion3D.bake_navigation_mesh()\n```\n\n```csharp\n\u002F\u002F 2D\nGetNode\u003CNavigationRegion2D>(\"NavigationRegion2D\").BakeNavigationPolygon();\n\n\u002F\u002F 3D\nGetNode\u003CNavigationRegion3D>(\"NavigationRegion3D\").BakeNavigationMesh();\n```\n\n### Async Navigation Baking\n\nNavigation baking can cause frame drops on large maps, so regions bake on a background thread by default: `bake_navigation_polygon()` (2D) and `bake_navigation_mesh()` (3D) take `on_thread = true` unless you pass `false`. Connect the region's `bake_finished` signal (use `CONNECT_ONE_SHOT`) to know when the mesh is ready. Threaded baking is unavailable on Web builds without thread support.\n\n> See [references\u002Fasync-baking.md](references\u002Fasync-baking.md) for the full GDScript and C# background-thread bake examples (2D and 3D).\n\n> **When to use async baking:** Procedurally generated levels, destructible terrain, or any scene where the navigation mesh must be rebuilt at runtime. The game continues running while the mesh bakes.\n\n### Navigation Layers\n\nNavigation layers let you separate walkable areas for different agent types (ground troops, flying units, large enemies).\n\n```gdscript\n# Assign layer bits on the NavigationRegion (Inspector or code)\n# Layer 1 = ground, Layer 2 = air, Layer 3 = large\n\n# On the NavigationAgent, set matching layers:\n$NavigationAgent2D.navigation_layers = 1   # ground only\n$NavigationAgent2D.navigation_layers = 2   # air only\n$NavigationAgent2D.navigation_layers = 1 | 2  # both (bitwise OR)\n```\n\n```csharp\n\u002F\u002F Assign layer bits on the NavigationRegion (Inspector or code)\n\u002F\u002F Layer 1 = ground, Layer 2 = air, Layer 3 = large\n\nvar navAgent = GetNode\u003CNavigationAgent2D>(\"NavigationAgent2D\");\nnavAgent.NavigationLayers = 1;       \u002F\u002F ground only\nnavAgent.NavigationLayers = 2;       \u002F\u002F air only\nnavAgent.NavigationLayers = 1 | 2;   \u002F\u002F both (bitwise OR)\n```\n\n> Set `navigation_layers` on both the **NavigationRegion** and the **NavigationAgent** so they match. Mismatched layers are one of the most common reasons an agent finds no path.\n\n---\n\n## 2. NavigationAgent2D Basic Usage\n\n### GDScript\n\n```gdscript\nextends CharacterBody2D\n\n@export var speed: float = 120.0\n\n@onready var nav_agent: NavigationAgent2D = $NavigationAgent2D\n\n\nfunc _ready() -> void:\n\t# velocity_computed fires when avoidance calculates a safe velocity\n\tnav_agent.velocity_computed.connect(_on_velocity_computed)\n\n\nfunc _physics_process(delta: float) -> void:\n\tif nav_agent.is_navigation_finished():\n\t\treturn\n\n\tvar next_pos: Vector2 = nav_agent.get_next_path_position()\n\tvar direction: Vector2 = (next_pos - global_position).normalized()\n\tvar desired_velocity: Vector2 = direction * speed\n\n\tif nav_agent.avoidance_enabled:\n\t\t# Hand desired velocity to the avoidance system; wait for the signal\n\t\tnav_agent.velocity = desired_velocity\n\telse:\n\t\tvelocity = desired_velocity\n\t\tmove_and_slide()\n\n\nfunc _on_velocity_computed(safe_velocity: Vector2) -> void:\n\tvelocity = safe_velocity\n\tmove_and_slide()\n\n\nfunc set_target(target_pos: Vector2) -> void:\n\tnav_agent.target_position = target_pos\n```\n\n**Key NavigationAgent2D properties:**\n\n| Property | Purpose |\n|---|---|\n| `target_position` | World-space destination |\n| `path_desired_distance` | How close to each waypoint counts as reached (default 20) |\n| `target_desired_distance` | How close to the final target counts as finished (default 10) |\n| `avoidance_enabled` | Enable RVO obstacle avoidance |\n| `radius` | Agent collision radius for avoidance |\n| `time_horizon_agents` | Seconds of avoidance look-ahead (tune to reduce jitter) |\n\n### C#\n\n```csharp\nusing Godot;\n\npublic partial class Enemy2D : CharacterBody2D\n{\n    [Export] public float Speed { get; set; } = 120f;\n\n    private NavigationAgent2D _navAgent;\n\n    public override void _Ready()\n    {\n        _navAgent = GetNode\u003CNavigationAgent2D>(\"NavigationAgent2D\");\n        _navAgent.VelocityComputed += OnVelocityComputed;\n    }\n\n    public override void _PhysicsProcess(double delta)\n    {\n        if (_navAgent.IsNavigationFinished()) return;\n\n        Vector2 nextPos = _navAgent.GetNextPathPosition();\n        Vector2 direction = (nextPos - GlobalPosition).Normalized();\n        Vector2 desiredVelocity = direction * Speed;\n\n        if (_navAgent.AvoidanceEnabled)\n            _navAgent.Velocity = desiredVelocity;\n        else\n        {\n            Velocity = desiredVelocity;\n            MoveAndSlide();\n        }\n    }\n\n    private void OnVelocityComputed(Vector2 safeVelocity)\n    {\n        Velocity = safeVelocity;\n        MoveAndSlide();\n    }\n\n    public void SetTarget(Vector2 targetPos) => _navAgent.TargetPosition = targetPos;\n}\n```\n\n---\n\n## 3. NavigationAgent3D Basic Usage\n\nA `CharacterBody3D` drives a `NavigationAgent3D` by calling `get_next_path_position()` each physics frame, flattening the direction on Y, and keeping gravity separate. With `avoidance_enabled` the desired velocity goes to `nav_agent.velocity` and movement happens in the `velocity_computed` handler; otherwise `move_and_slide()` is called directly. Targets are set through `target_position` and completion is checked with `is_navigation_finished()`.\n\n> See [references\u002Fnavigation-agent-3d.md](references\u002Fnavigation-agent-3d.md) for the full GDScript and C# `NavigationAgent3D` enemy example.\n\n---\n\n## 4. Steering Behaviors\n\nLightweight per-frame calculations (seek, flee, arrive, wander) that produce natural-looking movement without a navigation mesh. Combine them by summing the returned vectors, or pick one and assign it to `velocity` each `_physics_process` tick.\n\n> See [references\u002Fsteering-behaviors.md](references\u002Fsteering-behaviors.md) for the full GDScript and C# implementations of seek, flee, arrive (with deceleration ramp), and wander (with circle-projection jitter).\n\n---\n\n## 5. Patrol Patterns\n\nA `NavigationAgent2D` plus an array of `Marker2D` waypoints and a `Timer` for the pause at each point produces a clean patrol loop. Cycle the index on `wait_timer.timeout`, set `nav_agent.target_position` to the next waypoint, and gate movement on `is_navigation_finished()`.\n\n> See [references\u002Fpatrol-patterns.md](references\u002Fpatrol-patterns.md) for the full GDScript and C# waypoint-chain patrol with wait-timer pauses.\n\n---\n\n## 6. Behavior Tree Concept\n\nA behavior tree (BT) is a tree of nodes evaluated every tick. Three core node types:\n\n| Type | Succeeds when | Fails when |\n|---|---|---|\n| **Sequence** | all children succeed (AND) | any child fails |\n| **Selector** | any child succeeds (OR) | all children fail |\n| **Action** | the leaf action completes | the leaf reports failure |\n\nSequences model \"do A then B then C\". Selectors model \"try A, else try B, else try C\".\n\n> See [references\u002Fbehavior-trees.md](references\u002Fbehavior-trees.md) for the full lightweight BT implementation (BTNode base + Sequence \u002F Selector \u002F Action) and a worked enemy that uses \"chase OR patrol\", in both GDScript and C#.\n\n---\n\n## 7. Chase + Attack Pattern\n\nCombines NavigationAgent2D with a state machine. See the **state-machine** skill for the full FSM infrastructure.\n\n### States\n\n| State | Entry condition | Exit condition |\n|---|---|---|\n| PATROL | default \u002F player escaped | player enters detect_range |\n| CHASE | player in detect_range | player in attack_range OR player escaped |\n| ATTACK | player in attack_range | player left attack_range |\n\n> See [references\u002Fchase-attack.md](references\u002Fchase-attack.md) for the full GDScript and C# implementation (PATROL → CHASE → ATTACK transitions, attack cooldown timer, patrol-waypoint advancement, escape-range hand-off back to patrol).\n\n> For larger projects, extract each state into its own node class using the **state-machine** skill and inject the `NavigationAgent2D` reference from the parent.\n\n---\n\n## 8. Dedicated 2D Navigation Server (Godot 4.5+)\n\nPrior to Godot 4.5, `NavigationServer2D` was a thin frontend that delegated all work to the 3D navigation server internally. Godot 4.5 splits them into fully independent servers. The change is **transparent** — no API changes and no code migration is required — but it brings two practical benefits:\n\n- **Independence:** 2D navigation no longer runs through the 3D server — 2D maps, regions and agents are handled by their own implementation.\n- **Smaller exports for 2D-only games:** custom export templates can be compiled without the 3D navigation server (`disable_navigation_3d=yes`), reducing binary size.\n\n```gdscript\n# No code change needed — NavigationServer2D calls work identically.\n# The split is internal; you continue using NavigationServer2D as before.\n\n# Example: query a path directly via the server (unchanged API).\n# Not named get_path_to: that is Node.get_path_to(node) and cannot be overridden with another signature.\nfunc find_path_to(target: Vector2) -> PackedVector2Array:\n    var map: RID = get_world_2d().get_navigation_map()\n    return NavigationServer2D.map_get_path(\n        map,\n        global_position,\n        target,\n        true  # optimize path\n    )\n```\n\n```csharp\n\u002F\u002F No code change needed — NavigationServer2D calls work identically.\npublic Vector2[] FindPathTo(Vector2 target)\n{\n    Rid map = GetWorld2D().NavigationMap;\n    return NavigationServer2D.MapGetPath(map, GlobalPosition, target, true);\n}\n```\n\n> **2D-only projects:** Stock export templates still include 3D navigation. To drop it, compile custom export templates with the `disable_navigation_3d=yes` SCons option (Godot 4.5+). This is only safe if no 3D navigation nodes (`NavigationRegion3D`, `NavigationAgent3D`) are used anywhere in the project.\n\n---\n\n## 9. Common Pitfalls\n\n| Pitfall | Symptom | Fix |\n|---|---|---|\n| **Navigation mesh not baked** | Agent stands still; no path found | Bake the NavigationPolygon\u002FNavigationMesh before running, or call `bake_navigation_polygon()` at runtime after scene loads |\n| **`agent_radius` too large** | Agent can't fit through doorways or narrow corridors | Lower `agent_radius` on the NavigationPolygon\u002FNavigationMesh and rebake — the agent's own `radius` is for avoidance only and does not affect pathfinding |\n| **Avoidance jitter** | Agent stutters or oscillates when near other agents | Increase `time_horizon_agents` (try 2–4 s) or slightly lower `max_speed` on the agent |\n| **Path recalculation too frequent** | CPU spike each frame; agents lag | Add a `Timer` (0.2–0.5 s) and only set `target_position` when the timer fires, not every physics frame |\n| **Wrong navigation layer** | Agent ignores some regions or finds no path | Confirm `navigation_layers` bitmask matches between the NavigationRegion and the NavigationAgent |\n| **Target set before NavigationServer is ready** | Path is empty on the first frame | The map first synchronizes on a physics frame — in `_ready()`, `await get_tree().physics_frame` (or `NavigationServer2D.map_changed`) before setting `target_position` |\n| **Gravity ignored in 3D** | Agent floats or sinks into the floor | Always accumulate `velocity.y` from gravity separately; only zero out X\u002FZ from the nav direction |\n| **Baking causes frame drop** | Bake forced onto the main thread (`on_thread = false`), or parsing a very large scene | Keep the default threaded bake (`bake_navigation_mesh()`); connect `bake_finished` and never block waiting for it |\n\n> ⚠️ **Changed in Godot 4.7:** `NavigationServer3D.map_get_closest_point_normal(map, to_point)` now returns a normalized vector ([GH-119022](https:\u002F\u002Fgithub.com\u002Fgodotengine\u002Fgodot\u002Fpull\u002F119022)) — previously the returned surface normal could be unnormalized. Code that compensated by calling `normalized()` on the result keeps working; code that relied on the unnormalized magnitude breaks.\n\n---\n\n## 10. Checklist\n\n- [ ] NavigationRegion2D\u002F3D added to the scene with a NavigationPolygon\u002FNavigationMesh resource\n- [ ] Navigation mesh baked (edit-time or at runtime before the agent needs a path)\n- [ ] `navigation_layers` bitmask matches between NavigationRegion and NavigationAgent\n- [ ] `NavigationAgent2D`\u002F`NavigationAgent3D` is a **child** of the enemy node\n- [ ] `get_next_path_position()` called each physics frame, not `get_target_position()`\n- [ ] `velocity_computed` signal connected when `avoidance_enabled` is `true`\n- [ ] `is_navigation_finished()` checked before moving to avoid jitter at the destination\n- [ ] Path target updated via a throttle timer rather than every frame when following a moving player\n- [ ] `agent_radius` small enough to fit through the narrowest passage in the level\n- [ ] Gravity applied independently of horizontal nav velocity (3D only)\n- [ ] Large or dynamic maps keep the default threaded bake (`bake_navigation_mesh()`, `on_thread = true`) and wait for `bake_finished`\n- [ ] 2D-only projects on Godot 4.5+ can build custom export templates with `disable_navigation_3d=yes` to reduce export size\n",{"name":5,"description":7},"master","d7b26cdb5fae14d4ef7b713c5bf259395e75c3c6","skills\u002Fai-navigation",63,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter","https:\u002F\u002Fgithub.com\u002Fjame581","https:\u002F\u002Fjanmesarc.online\u002F","Software engineer. My biggest passion is game development.","2026-11-14 20:45:49",{"source":8,"skillName":5,"commands":44,"prompt":54,"zipAvailable":55},[45,48,51],{"tool":46,"command":47},"npx","npx skills add jame581\u002FGodotPrompter --skill ai-navigation",{"tool":49,"command":50},"bunx","bunx skills add jame581\u002FGodotPrompter --skill ai-navigation",{"tool":52,"command":53},"pnpm","pnpm dlx skills add jame581\u002FGodotPrompter --skill ai-navigation","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002FSKILL.md",true,[57,63,67,71,75,79],{"path":58,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":61,"sourceHtmlUrl":62},"references\u002Fasync-baking.md","REFERENCE","参考文档",1436,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fasync-baking.md",{"path":64,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":65,"sourceHtmlUrl":66},"references\u002Fbehavior-trees.md",6266,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fbehavior-trees.md",{"path":68,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":69,"sourceHtmlUrl":70},"references\u002Fchase-attack.md",8531,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fchase-attack.md",{"path":72,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":73,"sourceHtmlUrl":74},"references\u002Fnavigation-agent-3d.md",2627,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fnavigation-agent-3d.md",{"path":76,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":77,"sourceHtmlUrl":78},"references\u002Fpatrol-patterns.md",2992,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fpatrol-patterns.md",{"path":80,"resourceType":59,"resourceTypeDesc":60,"sizeBytes":81,"sourceHtmlUrl":82},"references\u002Fsteering-behaviors.md",6093,"https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fai-navigation\u002Freferences\u002Fsteering-behaviors.md",[84,104,125,155,179,196],{"skillNo":85,"name":86,"nameZh":6,"description":87,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":88,"categories":89,"keywords":90,"publishedAt":29},"01M6KRFE5BR2PSD08ZKDAS66R7","xr-development","Use when building VR\u002FAR\u002FXR applications — OpenXR setup, XROrigin3D, hand tracking, controllers, passthrough, and Meta Quest deployment in Godot 4.3+","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fxr-development\u002FSKILL.md",[],[91,92,28,93,94,95,96,97,98,99,100,23,101,102,103],"xr development","development","deployment","godot","vr","setup","tracking","godot 4","ar","hand","Meta","applications","quest",{"skillNo":105,"name":106,"nameZh":6,"description":107,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":108,"categories":109,"keywords":110,"publishedAt":29},"01M6KRF8GZTG1TAS506MFBSGFC","web-services","Use when a Godot game calls a web server — HTTPRequest, downloads, REST\u002FJSON APIs, auth headers, WebSocketPeer clients, TLS, retries, and keeping secrets out of the build. Not for game networking\u002FRPCs (multiplayer-basics) or browser export (web-export)","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-services\u002FSKILL.md",[],[111,112,113,114,115,116,117,118,23,28,94,119,120,121,122,123,124],"web services","web","services","tls","retries","calling","auth","downloads","clients","headers","secrets","json","build","REST",{"skillNo":126,"name":127,"nameZh":6,"description":128,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":129,"categories":130,"keywords":136,"publishedAt":29},"01M6KRF38Q4WSKAYFS56PG87T0","web-export","Use when shipping a Godot game to the browser — Web export preset options, threads vs no-threads and COOP\u002FCOEP headers, hosting on itch.io or your own server, PWA, JavaScriptBridge, user:\u002F\u002F persistence, audio and input limits, and load size","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fweb-export\u002FSKILL.md",[131],{"categoryNo":132,"categoryName":133,"taxonomyType":134,"taxonomyTypeDesc":135},"01JBSEEDCAT000000000000016","图像与多媒体","SCENARIO","使用场景",[112,137,138,139,140,141,142,143,120,144,145,28,146,147,148,149,150,151,23,152,153,154],"export","web export","threads","limits","shipping","size","options","hosting","input","Coop","preset","browser","game","io","load","pwa","Audio","server",{"skillNo":156,"name":157,"nameZh":6,"description":158,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":159,"categories":160,"keywords":169,"publishedAt":29},"01M6KREYFETEBH62ZTN6EZH2X3","using-godot-prompter","Bootstrap skill — establishes how to find and use GodotPrompter skills, with platform-specific tool mapping","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fusing-godot-prompter\u002FSKILL.md",[161,164],{"categoryNo":162,"categoryName":163,"taxonomyType":134,"taxonomyTypeDesc":135},"01JBSEEDCAT000000000000023","Skill与智能体开发",{"categoryNo":165,"categoryName":166,"taxonomyType":167,"taxonomyTypeDesc":168},"01JBSEEDCAT000000000000032","设计师","PROFESSION","适用职业",[94,170,171,172,173,23,174,175,176,177,178],"using godot prompter","find","with","bootstrap","tool","platform","mapping","how","how to",{"skillNo":180,"name":181,"nameZh":6,"description":182,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":183,"categories":184,"keywords":185,"publishedAt":29},"01M6KRER5G7EQWKGAFN8QJKQ69","tween-animation","Use when implementing tweens — property animation, method tweening, chaining, parallel sequences, easing, and common UI\u002Fgameplay motion recipes","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Ftween-animation\u002FSKILL.md",[],[186,187,23,188,189,190,191,192,193,194,27,28,195],"tween animation","Animation","motion","parallel","gameplay","chaining","ui","recipes","common","sequences",{"skillNo":197,"name":198,"nameZh":6,"description":199,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":200,"categories":201,"keywords":202,"publishedAt":29},"01M6KREKGCQMVDV8WX7HWX8BZG","state-machine","Use when building a state machine or refactoring logic into one — enum, node, and resource-based FSM patterns with trade-offs. Not for adding states to an existing one","https:\u002F\u002Fgithub.com\u002Fjame581\u002FGodotPrompter\u002Fblob\u002Fmaster\u002Fskills\u002Fstate-machine\u002FSKILL.md",[],[203,204,205,94,28,25,206,207,208,209,172,23,27,210],"state","state machine","machine","node","fsm","state machines","trade","trade-offs"]