Just to break it down how it’s done ^^
You have this line which will throw an index out of bounds exception.
return world.blocktypes[voxelMap[x, y, z]].isSolid;
Those errors are thrown by arrays or colliections whenever you pass in an index that is either too large or too small. You have two array accesses in the same line. So first step is, break it up
byte blockIndex = voxelMap[x, y, z];
blockType block = world.blocktypes[blockIndex];
return block.isSolid;
This is just breaking it up into individual lines. The advantage is that if an error occurs now, you can tell by which part. We haven’t done any error checking yet. This is the same line of code, just separated into individual lines. Now we can do some simple checks or print out the values.
Debug.Log($"Getting block from voxelMap[{x}, {y}, {z}]");
byte blockIndex = voxelMap[x, y, z];
Debug.Log($"Got block index {blockIndex}");
Debug.Log($"Size of blocktypes: {world.blocktypes.Length}");
blockType block = world.blocktypes[blockIndex];
if (block == null)
Debug.LogError($"Block with index {blockIndex} seems to be null in the blocktypes array");
return block.isSolid;
When running with this code you should get a ton of information to figure out where the issue is.
My guess may be that your FloorToInt may result in a negative value since you use Vector3 which are float values, when you floor them and they are ever so slightly below 0, it would floor to -1. But lets see what you get.
Depending on what your source coordinates actually are, using RoundToInt probably makes more sense in many cases. Especially when the coordinates are actually on the grid lines. With floor it will be luck if you hit one or the other values.