# Pathing question

I’m trying to make work on tile based movement still, but I’m having a hard time figuring out a few things, and so I was hoping someone might be able to help me.

Here’s how the pathfinding I’ve set up works right now.

I’d like to have nodes be able to connect so that pathfinding would work like this though:

How do I go on about doing that, is it even possible? Thanks in advance.

Hi

Err… So the graphs should ONLY allow diagonals in between diagonal obstacles.
Sure, that is possible (it’s just basically the opposite of what people usually want).
You will need to modify some code however. Take a look at the GridGraph.CalculateConnections method. That method calculates how nodes connect to other nodes.

Thanks for the quick answer, I appreciate it!

I struggled to find a lot of information about the method and to figure out how it works, but I think I have a vague idea of how it would work now. I’m still a newbie coder and I have a lot to learn so if I need to modify the code in the way I assume I’ll have to it’s too advanced for me (right now).

I might be wrong though and I might be missing something, it’s possible that it’s easier than I think. Feel free to throw in some example on how I can use the method or where I can learn more about it and I’ll be the happiest person alive this day.

Tack Aron.

I think it should be solved changing these lines:

`if (neighbours == NumNeighbours.Eight) { change to if (true) {`
and
`if (corners[i] == 2) { change to if (corners[i] == 0) {`

make sure Cut Corners is disabled in the grid graph settings.

GridNode other = nodes[index+neighbourOffsets[i+4]]; ^ This line errors when I did those changes.

IndexOutOfRangeException: Array index is out of range. (http://pastebin.com/28WHKB5p)

Don’t worry, I don’t expect you to code this for me, it’s my own fault for experimenting with things way above my level. It’s interesting though, can’t help myself.

Ah right.
You need to insert these lines right before the line that threw the exception.

`
int nx = x + neighbourXOffsets[i+4];
int nz = z + neighbourZOffsets[i+4];

if (nx < 0 || nz < 0 || nx >= width || nz >= depth) {
continue;
}`

Otherwise it will try to create connections to nodes that don’t exist.

You can see the comment in the code a few lines above:
`//We don't need to check if it is out of bounds because if both of the other neighbours are inside the bounds this one must be too`
the changes we made previously invalidated that assumption.

It works just as I had hoped it would, thank you so much.