You should really just look up the DDA algorithm as previously suggested, it is 'far' simpler implementation than what you have described.

My description was very poor. The algorithm I wrote is really simple, but it requires that your ray is inside the cell that you're finding the neighbor of.

Here's a simple version with a single value:

int sign = Math.Sign(direction) float distance; if(sign == 1) { distance = 1 - value; } else if(sign == -1) { distance = -value; } else { distance = infinity; }

After you get the distance to the next face for each component (X, Y, and Z), you figure out which face you will get to first by dividing the distance by the direction.

Once you know which face you will encounter first, you know which cell is the next cell. The problem I'm having is that I rely on the position of the ray to trace through the cells.

Sorry that I'm being very vague, I have ADHD, and it's really hard for me to articulate what's going through my mind. All I see is a visualization of my algorithm, and I could give you the code, but it wouldn't make sense since there are a few things that you'll likely not know what's happening.