NavMeshPlus

repository·master·Indexed 25 days ago

https://github.com/h8man/navmeshplus

An enhanced version of Unity's NavMeshComponents designed for 2D pathfinding. It allows for the automatic generation of navigation meshes from 2D geometry such as Tilemaps, Sprites, and Collider2D. The package provides core components including NavMeshSurface, NavMeshModifier, NavMeshModifierVolume, and NavMeshLink to manage navigation surfaces and agent movement in 2D environments.

Tokens
1.1K
Snippets
1
Records
8
Agent score
31%

What's inside NavMeshPlus

  1. Core components for NavMesh building

    master

    NavMeshPlus provides four primary components to control NavMesh generation and usage at both runtime and edit time:

    • NavMeshSurface: Used for building and enabling a NavMesh surface for a specific agent type.
    • NavMeshModifier: Affects NavMesh generation by modifying NavMesh area types based on the object's transform hierarchy.
    • NavMeshModifierVolume: Affects NavMesh generation by modifying NavMesh area types based on a defined volume.
    • NavMeshLink: Used to connect two surfaces (either the same or different) for a specific agent type.
  2. How NavMeshPlus 2D Navigation works

    master

    NavMeshPlus extends Unity's standard NavMeshSurface to support 2D environments through the following mechanism:

    1. Base Implementation: It uses Unity's NavMeshSurface as its foundation.
    2. World Bounds: It calculates the world bounds of your scene.
    3. Source Collection: It implements specialized collectors for 2D sources, specifically Tiles, Sprites, and 2D Colliders.
    4. Mesh Creation: It creates a walkable mesh box based on the calculated world bounds.
    5. Conversion: It converts these 2D elements into sources that the NavMeshBuilder can process, similar to how 3D geometry is handled in standard NavMesh workflows.
  3. Bake a 2D Navigation Mesh

    master

    NavMeshPlus allows you to generate navigation meshes automatically from 2D scene geometry like Tilemaps, Sprites, and Collider2D. Follow these steps to bake a surface:

    1. Create a Controller Object: Create an Empty GameObject at the root of your scene.
    2. Add Components:
      • Add the Navigation Surface component to the object.
      • Add the NavMeshCollectSources2d component immediately after it.
    3. Orient the Surface: Click Rotate Surface to XY on the component. This rotates the surface to face a standard 2D camera (rotation: x:-90, y:0, z:0).
    4. Define Obstacles: Add a Navigation Modifier component to your scene objects (obstacles) and override the area to mark them as non-walkable.
    5. Bake: In the Navigation Surface component, click Bake.
  4. Set up NavMeshPlus in Unity

    master

    You can integrate NavMeshPlus into your Unity project using one of three methods. Ensure Git is installed and added to your system path.

    Method 1: Manual Download

    Clone or download the repository directly into your project's Packages/com.h8man.2d.navmeshplus folder.

    Method 2: Package Manager Manifest

    Add the following line to the dependencies section of your Packages/manifest.json file:

    "com.h8man.2d.navmeshplus": "https://github.com/h8man/NavMeshPlus.git#master"

    Method 3: Add Package via Git URL

    1. Open the Unity Package Manager.
    2. Click the + icon.
    3. Select Add Package from git URL....
    4. Paste the following URL:

    https://github.com/h8man/NavMeshPlus.git

  5. Install NavMeshPlus in Unity

    master

    To use NavMeshPlus in your Unity project, follow these steps:

    1. Select the correct branch: Ensure you download or clone the branch that matches your Unity editor version (e.g., master for the latest, or specific branches like 2018.3, 2017.2, etc.).
    2. Installation methods:
      • Full Project: Clone or download the repository and open the project in Unity.
      • Existing Project: Copy the contents of Assets/NavMeshComponents directly into your existing project's Assets folder.
    3. Requirements: Requires Unity 5.6 or newer.

    Note: It is highly recommended to backup your project before opening it with a beta build, as APIs are subject to change.

  6. Reference of NavMeshPlus components and extensions

    master

    The following components and utilities are provided by the NavMeshPlus extension system:

    Core Components

    • NavMeshLink: Defines connections between different parts of the NavMesh.
    • NavMeshModifier: Used to modify the navigation properties of specific scene objects.
    • NavMeshModifierVolume: Defines a volume in the scene to apply navigation modifiers.
    • NavMeshSurface: The primary component for baking the mesh. It includes the following sub-components/collectors:
      • NavMeshCollectSources2d
      • NavMeshCollectRootSources2d
      • NavMeshCacheSources2d

    Utilities

    • NavMeshExtensionsProvider.cs
    • NavMeshBuilder2d.cs
    • NavMeshExtension.cs
    • NavMeshBuilderState.cs