Infohazard.HyperNav 2.0.0
A pathfinding and avoidance solution for volumetric and omnidirectional navigation.
Loading...
Searching...
No Matches
HyperNav Documentation

Table of Contents

  • HyperNav Documentation
    • Table of Contents
    • Introduction
    • Documentation and Support
    • License
    • Installation
      • Prerequisites
      • Asset Store
      • Package Manager (Git URL or Submodule)
    • Setup
      • General Setup
      • SRP Setup
    • Demos
      • HyperNavDemo (Volumetric Pathfinding)
      • HyperNavAvoidanceDemo (Pathfinding Avoidance)
      • HyperNavAvoidanceScaleDemo (Many-Agent Standalone Avoidance)
      • HyperNavFloatingOriginDemo (Floating Origin System)
      • HyperNavDynamicLinkBakingDemo (Runtime External Link Generation)
      • HyperNavRuntimeBakingDemo (Runtime Data Generation)
      • HyperNavManualLinkDemo (Manual Toggle-able Links)
      • HyperNavSurfaceDemo (Omnidirectional Surface Pathfinding)
      • HyperNavSurfaceAndVolumeDemo (Hybrid Walking/Flying Character)
    • Features Guide
      • Volume and Surface Setup
      • External Links
      • Pathfinder Setup
      • Agent Setup
      • Avoidance
      • Moving Volumes and Floating Origin

Introduction

HyperNav is a navmesh-like system for implementing volumetric and omnidirectional navigation and 3D obstacle avoidance. Unlike a navmesh, which is bound to walkable surfaces, HyperNav creates volumes in which characters can navigate on all three axes, and surfaces on which characters can navigate with any upwards direction. I developed it for Astral Horizon, an FPS with 6-DOF gameplay.

Documentation and Support

API Docs

Tutorial Playlist

Discord

License

HyperNav uses the standard Unity Asset Store per-seat license for tools.

Installation

Prerequisites

HyperNav depends on the Infohazard.Core library, which you can get from the Asset Store or as a Package Manager package from Github. Regardless of how you install it, you should do so before importing HyperNav. You can see more information about the core library here.

HyperNav also requires UniTask, which can be installed as a package manager git package or a .unitypackage file.

Finally HyperNav has two additional package manager dependencies: burst and collections. However, these will automatically be installed when you import it, so no need to do anything here.

Asset Store

The main way to install HyperNav is through the asset store. Just install it as you would any other asset, and make sure you allow Unity to update package manager dependencies.

Package Manager (Git URL or Submodule)

Because HyperNav is a paid asset, the Github repository is not open source. However, if you wish to contribute to HyperNav and have purchased a seat, please feel free to email me and I can look into getting you read access to the repository.

Setup

General Setup

The only setup required beyond installation is to add references to the Infohazard.HyperNav assembly if you are using an assembly definition. If you are using the default assemblies (such as Assembly-CSharp), nothing is needed here.

SRP Setup

If you are using a scriptable render pipeline (URP, HDRP, etc) and wish to run the demos, you will need to upgrade the materials using your render pipeline's material upgrade system. The materials you'll need to upgrade are in:

  • Assets/Plugins/Infohazard/Demos/Infohazard.HyperNav/Materials
  • Assets/Plugins/Infohazard/Demos/Shared Demo Assets/Materials
  • Assets/StarterAssets/ThirdPersonController/Character/Materials

Demos

The following demo scenes are provided to cover the various features of HyperNav. They are found in Assets/Plugins/Infohazard/Demos/Infohazard.HyperNav/Scenes.

HyperNavDemo (Volumetric Pathfinding)

This scene demonstrates how to set up NavVolumes and a NavPathfinder, and use NavAgent and SplineNavAgent to find paths. Run the demo and click anywhere on the right side of the screen to set a destination, and use the WASD keys to rotate the camera on the left side of the screen.

HyperNavAvoidanceDemo (Pathfinding Avoidance)

This scene demonstrates how you can use avoidance along with NavAgents to avoid agents getting stuck in a narrow maze. Try turning off avoidance by setting the agents' avoidance weights to zero to see the difference it makes.

HyperNavAvoidanceScaleDemo (Many-Agent Standalone Avoidance)

This scene deomonstrates how you can use avoidance without a NavAgent. It also shows that the avoidance system performs well even with a huge number of agents all avoiding one another.

HyperNavFloatingOriginDemo (Floating Origin System)

This scene deomonstrates how you can use HyperNav with a floating origin system. This is useful in very large scenes where you need to shift all objects such that the player remains close to the origin.

HyperNavDynamicLinkBakingDemo (Runtime External Link Generation)

This scene demonstrates how you can generate volume external links at runtime in order to support a runtime modular building system. This requires having one volume per module, but is preferable to baking the entire volume data at runtime (it is much, much faster).

HyperNavRuntimeBakingDemo (Runtime Data Generation)

This scene demonsstrates how you can generate the entire volume data at runtime in order to support fully procedurally generated maps. Note that while runtime generation is supported, it is still quite performance intensive. I do not recommend generating data during gameplay; rather you should try to do it during a loading screen if possible (or better yet, use modular volumes and simply generate the links at runtime).

HyperNavManualLinkDemo (Manual Toggle-able Links)

This scene shows how you can create manual external links that can be turned on or off. This is useful, for example, if you have doors that can be locked and should only be considered navigable when they are unlocked. Manual external links can also connect different regions in the same volume, rather than only separate volumes.

HyperNavSurfaceDemo (Omnidirectional Surface Pathfinding)

This scene shows how you can use the NavSurface component to enable pathfinding on complex omnidirectional surfaces. The agent behaves as a normal walking character, but it can walk on surfaces pointing in any direction. Instead of being constrained to a single upright direction as in a traditional NavMesh, a NavSurface allows arbitrary upright directions anywhere on the surface.

HyperNavSurfaceAndVolumeDemo (Hybrid Walking/Flying Character)

Inspired by Astral Horizon, this scene shows how you can have a character able to both walk on surfaces and fly in volumes, and transition dynamically between them. The volume and surface take up the same area and are connected by external links.

Features Guide

Volume and Surface Setup

The first step to setup navigation in your scene is to create a navigable area (NavSurface, NavVolume, or both), using one of the menu items:

  • Tools > Infohazard > Create > Nav Volume - create NavVolume for volumetric navigation.
  • Tools > Infohazard > Create > Nav Surface - create NavSurface for omnidirectional surface-based navigation.
  • Tools > Infohazard > Create > Nav Volume + Surface - create a single area for both types of navigation.

Baking

Once your parameters are configured, you can bake the nav area! Just hit the "Bake" button and wait for it to finish (it should be fairly quick). If the baking is taking a long time, consider breaking your area up into multiple smaller areas. By default, when baking is done, you should see the baked results rendered as a blue mesh in the scene view when the area is selected.

Runtime Baking

To regernate area data at runtime, use NavVolumeUpdate.GenerateVolumeData or NavSurfaceUpdate.GenerateSurfaceData with the area you wish to update. This operation is quite performance intensive, so it is not recommended to do it during gameplay. Instead, try to do it during a loading screen if possible. Additionally, you will probably only want to generate one area at a time, as generating multiple areas will cause thread starvation and tank the framerate.

External Links

If you are using multiple areas (including using a volume + surface), you most likely will want agents to be able to find paths between them. This is accomplished using external links. Simply use the "Generate External Links" button after all areas are baked, or, for convenience, "Generate All External Links" to generate links on all loaded areas. Once the external links are generated, you can visualize them in each area's visualization settings.

Note that if you re-bake an area, you will need to regenerate not only its external links but the external links of all of its neighbors. If you don't do this, you will get links leading to the wrong region, and potentially paths that cross through impassible areas. The "Generate All External Links" button comes in handy here.

Manual Links

In addition to the auto-generated links, you can create manual external links. These links can be toggled on or off at runtime, and can connect different regions in the same volume, rather than only separate volumes. To create a manual link, use the menu item Tools > Infohazard > Create > Manual Nav Link, and use the gizmos to position the endpoints of the link in the desired areas. The next time you generate the volumes' external links, the manual links will be included (note that generating the links is required for the manual links to be included in the pathfinding data).

Runtime Link Generation

To regenerate external links at runtime, use NavAreaExternalLinkUpdate.GenerateExternalLinks with the areas you wish to update.

Pathfinder Setup

Before you can start pathfinding, you also need to create a NavPathfinder, using the menu item Tools > Infohazard > Create > Nav Pathfinder. You can create a NavPathfinder in each scene that needs one, or you can create one that persists through level loading.

Agent Setup

The final step to start pathfinding is to set up agents. A NavAgent is the easiest way to start finding paths from code. Simply add the NavAgent to your GameObject, set its Destination, and read its DesiredVelocity.

Agent-Driven Movement

A NavAgent simply provides a DesiredVelocity, so you'll need another script to actually move the object. You can either use your own movement code that reads DesiredVelocity, or use the provided SimpleNavAgentMover script to handle some common situations.

Spline Agent Setup

If you wish to use the spline path system to achieve smoother navigation paths, simply replace the NavAgent with a SplineNavAgent. SplineNavAgent provides the same properties as NavAgent (as it is a subclass) with some additional properties. SplineNavAgent works on both volumes and surfaces, but the actual splines will only be used for volume-based navigation; on surfaces it will revert to the NavAgent behavior.

Avoidance

Whereas NavAgent and SplineNavAgent are used to plan paths between two points, avoidance is used to steer clear of obstacles that might obstruct that path. These obstacles might be moving objects or even other navigating agents, so they can't easily be baked into the area data. Instead, you should use the obstacle avoidance system.

AvoidanceManager Setup

In order to use avoidance, there must be an AvoidanceManager present in your scene. To create an AvoidanceManager, use the menu item Tools > Infohazard > Create > Avoidance Manager.

AvoidanceAgent Setup

If you want an object to avoid obstacles, you should add an AvoidanceAgent script. This script needs to know the maximum speed the agent can travel at, the agent's size, and several other properties.

AvoidanceAgent With NavAgent

When you want to use avoidance with a NavAgent or SplineNavAgent, the usage is simple. The NavAgent should have a button to create an AvoidanceAgent on the object and instantly connect it to the NavAgent. The NavAgent will handle the input and output velocity for the AvoidanceAgent, so you can simply read the NavAgent's DesiredVelocity which now includes avoidance. You will still need to configure the max speed on the AvoidanceAgent for it to work properly.

AvoidanceAgent Usage

You can use an AvoidanceAgent without a NavAgent. For this use case, you must supply an input velocity (the velocity the agent wants to move in) and read its AvoidanceVelocity (the velocity it should move in to avoid obstacles). The input velocity is provided via a delegate, allowing you to connected it to whatever source you want.

AvoidanceObstacle Setup

While AvoidanceAgents will automatically avoid each other, you may wish to add additional obstacles that are not agents. This can be done using AvoidanceObstacleBase or any of its subclasses (which determine the current velocity using different methods). Just add one of these scripts to an object and the obstacle is good to go:

  • AvoidanceObstacleBase: Does not calculate a velocity, so it is assumed to be stationary. You can inherit from it to add your own velocity calculations.
  • SimpleAvoidanceObstacle: Calculates its velocity by measuring delta position / delta time every frame.
  • RigidbodyAvoidanceObstacle: Uses the current velocity of an attached Rigidbody component.

Moving Volumes and Floating Origin

You may need to occasionally move NavVolumes, either individually or all together. When this occurs, the native data for the volumes needs to be updated. For moving individual volumes, you can enable AutoDetectMovement on the volumes and the data updating will be handled automatically. For moving all volumes at once such as in a floating origin system, it will be more performant to use NavVolume.UpdateAllTransforms() after they are moved.

Moving Volume Limitations

In both cases, any pathfinding operations currently underway will automatically be restarted. Any agents that already have paths, however, will need to be manually stopped by calling Stop() and the destination re-supplied in shifted space.

Moving volumes does update the external link positions, so two volumes with links to one another that move together will have the links updated correctly. However, if one volume moves relative to another volume that it shares links with, the link positions will stay relative to the originating volume. To account for this, you'll need to regenerate the links at runtime.

While individual moving volumes are supported, note that when a volume is moved, any calculating paths will be canceled. So if a volume is moving every frame, the paths will be continuously canceled before they can complete. You can get past this by putting the NavPathfinder in Instantaneous mode, but that will likely lead to stutters.