Mapping a 3D Grid across rough terrain.

My 3D tile based grid game has a system that grabs all the tiles, then uses its Vecor3Int as grid coordinates. On a flat, this works great - but if I want to vary terrain height, add ramps, and so on. Which causes a lot of errors and things being rounded up or down to the wrong layer. This creates massive errors in pathfinding because the map references are all shunted up or down, basically at random.

That means an enemy on one layer is suddenly faced with deciding if the layer above OR below is a valid place to go.

What I’m wondering here is:

  1. Is there a way to automatically create distinct layers in my 3D grid map without errors?
  2. Should I just totally abandon this and have my enemies navigate some other way? Bearing in mind that the tiles will eventually be part of a random content generation & modding system?

I could botch this by giving every tile a parent gameObject on the right layer BUT this would create its own set of issues I’d rather avoid.

It kinda comes down to the topology you want.

Simplest would be if the logical part of the level is just a sheet of rubber stretched tightly over the terrain.

Second simplest would be that but with cuts in it, such as cliffs or the sides of ramps where you cannot traverse.

The two items above all assume only ONE position per cell, eg, no bridges or floors, so very simple.

The most complex topology would allow for bridges and floors of a building, eg, you could be at a particular square at different altitudes and have different options open, eg, can’t step on/off the sides of a bridge, but you can walk under it.

The latter approach would require you to encode x, y AND altitude as input to your traversable graph of locations, as well as provide some kind of way for you to author what is connected to what.

Personally I find it easiest to start with some simple editor tools, even if it is just OnDrawGizmos() type visualizations, along with explicit connections between the cells, and even if it is just a little 4x4-cell level, and then get that working with a simple “Walk around and don’t let you go where you cannot go” type setup.

When you reach that point you can decide if you want to write more involved editors or visualizers to create your levels at scale.

Currently I assume every tile and creature fits in a 1x1x1 cube, and that the position of these cubes varies with the terrain somewhat. So, basically, you have the tiles laid on top of the terrain. Every cube location is logged in a Dictionary, using its Vector3Int as the key. It’s very efficient, except for the little issue that I cannot vary the height using this model.

Basically my 3D world and my coding world have a conflict I’m not sure how to resolve, and it’s stalling my development as It needs to be fixed before I build anything on top of it. I’ve basically built everything else, so I’m sort of screwed unless I can make this work.

Basically what I really need is a way to record and retrieve the grid position of every square accurately, regardless of the actual topology. Though I’m beginning to think I’m just going to have to fake my way around it with parenting or something tbh. Unfortunately, it would be too much of a pain to artificially tag every square individually while I’m laying it.

This wouldn’t be an issue, except that it would really help me with my pathfinding.