- Home /
Creating a 3D Navmesh for a Spacegame
Hey guys. I am trying to create a little Space Shooter. I wanted to use Unity's built-in NavMeshAgent, but the problem is that it needs a NavMesh. And I don't know how, or if you can create a 3 dimensional NavMesh. Is there any way I can make the Spaceships navigate in x, y and z? Or do I need an invisible layer in order to make the NavMeshAgent work?
A node-based pathfinding system is probably not the best solution for a game in which the world is almost completely empty with only a handful of obstacles over vast distances (some planets or asteroids, and other ships). A much simpler solution that is more suited to this environment would be one that utilized raycasting; cast a ray from origin to the target location and if there's something in the way, offset the current raycast target position until the path is clear again, and then cast again from this position toward the original target, and so on. Each step, you add the offset positions to a list which will then serve as the waypoints an objects needs to travel along.
Answer by JonPQ · Jul 22, 2019 at 09:43 PM
Nav meshes work in 3D space, but the surfaces of the mesh are really 2D. or 2.5-D they can follow stairs and slopes up and down, and go over and under itself... but doesn't lend itself well to a truly 3d space. Depending on your level (space) layout.... I would suggest that you'd want a node based system instead... more like a 3d cube of node points... each point in space would be free or not-useable (inside solid object) then at each node you'd do a bunch of ray casts, to nearby nodes to build a tree. Then you could use modified A* search algorithm to find path to follow in arbitrary 3d space. You could also choose to make a tree where the nodes your raycast, are also further than just the nearest nodes, it would take longer to prepare your tree, but get better results. If your map is simple... you could probably place the nodes and link them by hand, and make a simple tool to connect nodes, visualizing them using OnDrawGizmos()
For A*, you could write it yourself, or buy one on asset store that comes with source code, and modify it a bit for 3d support.
Your answer
Follow this Question
Related Questions
How to edit baked navigation for better accuracy? 0 Answers
Unexpected Navmesh agent rotation 0 Answers
Unity Navagation Ground Mapping 1 Answer
NavMesh agent snaps to wrong mesh 0 Answers
Duplicated NavMesh Agents not moving 0 Answers