精選文章

SmallBurger Asset Home

  SmallBurger

2025年5月12日 星期一

An Overview of SpriteRendererNAV

 


The motivation behind developing SpriteRendererNAV stemmed from the desire to recreate the NAVMesh pathfinding tool, originally developed for a 2D scene editor in Cocos2d-X, within Unity. Additionally, users have expressed the need for a quick development tool that includes pathfinding functionality for 2D scenes, but they do not want to use the traditional A* algorithm, as it often creates a grid-like appearance unless the grid is made extremely fine, which can severely impact performance. As a result, I embarked on the development of the SpriteRendererNAV asset.

The related videos for the custom Cocos2d-x scene editor:


The entire process is not very complicated. The following are the steps involved:

  1. Add the World quad mesh to MeshBuildSources.
  2. Create Mesh colliders for all SpriteRenderers.
  3. Use Physics.BoxCast to scan all Colliders in the scene and generate the corresponding block line data.
  4. Based on the block line data, create a block line mesh and add it to MeshBuildSources.
  5. Create NavMeshData, use NavMeshBuilder.UpdateNavMeshData, and pass in MeshBuildSources.
  6. Finally, add the generated NavMeshData to the NavMesh.

For pathfinding testing, the PathCalculator script is provided to directly call NavMesh.CalculatePath and add NavMeshObstacle (Dynamic Obstacle) for pathfinding tests.

The related videos:


You can find it here:

沒有留言:

張貼留言