Added AI generated Navmesh tutorial
This commit is contained in:
parent
413a64cdce
commit
7c2cdb8cbb
12
.obsidian/workspace.json
vendored
12
.obsidian/workspace.json
vendored
@ -184,13 +184,19 @@
|
||||
"daily-notes:Open today's daily note": false,
|
||||
"templates:Insert template": false,
|
||||
"command-palette:Open command palette": false,
|
||||
"obsidian-git:Open Git source control": false
|
||||
"obsidian-git:Open Git source control": false,
|
||||
"copilot:Copilot Chat": false
|
||||
}
|
||||
},
|
||||
"active": "b28fe42437006820",
|
||||
"active": "be6bc070960af330",
|
||||
"lastOpenFiles": [
|
||||
"Tutorials/Enemy AI - Unity NavMesh (tutorial).md",
|
||||
"Scripting/Classes/Physics/Raycast.md",
|
||||
"Scripting/UnityEngine.AI/Classes/NavMesh.md",
|
||||
"Scripting/Classes/Physics",
|
||||
"Scripting/Classes",
|
||||
"copilot-conversations/Robot_can_you_search_the_web@20241023_164312.md",
|
||||
"copilot-conversations",
|
||||
"Tutorials/Enemy AI - Unity NavMesh (tutorial).md",
|
||||
"Scripting/UnityEngine.AI/Classes",
|
||||
"Scripting/UnityEngine.AI",
|
||||
"Scripting",
|
||||
|
0
Scripting/Classes/Physics/Raycast.md
Normal file
0
Scripting/Classes/Physics/Raycast.md
Normal file
@ -0,0 +1,80 @@
|
||||
### NavMesh Overview
|
||||
|
||||
The **NavMesh** system is your go-to for pathfinding and AI movement in 3D environments. Imagine you're baking a map that your game characters can navigate on — that’s what the NavMesh is. You can tweak how characters move, handle obstacles, and even create custom paths.
|
||||
|
||||
---
|
||||
|
||||
### Static Properties
|
||||
|
||||
| Property | Description |
|
||||
|---|---|
|
||||
| `AllAreas` | Think of this as selecting *everywhere* your AI can walk. |
|
||||
| `avoidancePredictionTime` | How far in the future Unity should predict AI avoiding each other. |
|
||||
| `onPreUpdate` | A callback you can hook into right before the NavMesh updates. |
|
||||
| `pathfindingIterationsPerFrame` | Controls how much pathfinding Unity does each frame. More means better accuracy but slower frames. |
|
||||
|
||||
---
|
||||
|
||||
### Key Static Methods (Chill Teacher Mode)
|
||||
|
||||
**1. `AddLink`**
|
||||
|
||||
This method is all about creating *custom* paths between two points on the NavMesh — perfect if you want shortcuts or special routes.
|
||||
|
||||
```csharp
|
||||
NavMesh.AddLink(new NavMeshLinkData()
|
||||
{
|
||||
startPosition = new Vector3(0, 0, 0),
|
||||
endPosition = new Vector3(10, 0, 10),
|
||||
width = 2.0f
|
||||
});
|
||||
```
|
||||
- **Use Case:** You want to build a bridge between two points that aren't directly connected.
|
||||
|
||||
---
|
||||
|
||||
**2. `CalculatePath`**
|
||||
|
||||
Wanna know how your AI is gonna move from Point A to Point B? Use this to calculate that path ahead of time.
|
||||
|
||||
```csharp
|
||||
NavMeshPath path = new NavMeshPath();
|
||||
NavMesh.CalculatePath(startPos, endPos, NavMesh.AllAreas, path);
|
||||
```
|
||||
- **Cool Trick:** You can check if the path is valid or not (`path.status`), which helps avoid bad routes.
|
||||
|
||||
---
|
||||
|
||||
**3. `FindClosestEdge`**
|
||||
|
||||
Ever needed to know where the closest boundary is in your NavMesh? This one’s handy for that!
|
||||
|
||||
```csharp
|
||||
NavMeshHit hit;
|
||||
if (NavMesh.FindClosestEdge(transform.position, out hit, NavMesh.AllAreas))
|
||||
{
|
||||
Debug.Log("Edge found at: " + hit.position);
|
||||
}
|
||||
```
|
||||
- **Why It’s Useful:** It's like your AI has a radar for walls and limits. Use it to keep them in bounds.
|
||||
|
||||
---
|
||||
|
||||
**4. `Raycast`**
|
||||
|
||||
This is like drawing an invisible line to see if the AI can walk straight to a point.
|
||||
|
||||
```csharp
|
||||
NavMeshHit hit;
|
||||
if (!NavMesh.Raycast(startPos, endPos, out hit, NavMesh.AllAreas))
|
||||
{
|
||||
Debug.Log("Line of sight is clear!");
|
||||
}
|
||||
```
|
||||
- **Pro Tip:** Use it to test if obstacles are in the way, so you can reroute AI.
|
||||
|
||||
---
|
||||
|
||||
These examples should give you a good starting point to experiment and make your AI navigation smarter. Keep in mind, you’ll need to bake your NavMesh in the scene first!
|
||||
|
||||
**Generated by ChatGPT**
|
Loading…
Reference in New Issue
Block a user