maandag 2 april 2018

Procedural Dungeon - Part 3: making the dungeon gameplay ready

Procedural Dungeon - Part 3

Introduction: 

In the previous posts I showed you how I have laid a solid foundation for the procedural dungeon. Now all we need to start using it is adding collision and textures.
So let's get started!

Collision: 

All I had to do was add a mesh collider component in code and set the sharedMesh to the wall-mesh I already generated.
It really can't get any easier ;)

Creating a player controller: 

Not so much special stuff about this.
For the player I created a simple player controller, where you can walk, sprint and hit with a hammer. Furthermore I came up with the idea that you can spawn stuff to find out where you have been already in the maze. So I made this too.

Pathfinding: 

What I really struggled with was the pathfinding for the AI. Luckily I found out that you can bake a navmesh surface over a mesh in game-mode. To do this, I first had to find out how to make a custom ground mesh from the data that I already had. 
After I managed to do so, I only had to attach the navmeshsurface to it and build the navmesh.

If you want to check out the navmesh components git that I've used, check it out here:
https://github.com/Unity-Technologies/NavMeshComponents

Spawning Objects: 

For the spawning I retrieved the data from the rooms, and used a random tile-position as a spawn position. 
To prevent stuff from being spawned at the same room I created the following recursive function: