Is there a way to restrict movement to X and Y for 2d?

Hi,

I have a set up where I’m using A* in a top-down 2d game with click-to-move. I generated the graph on X and Y just fine and have my characters generating and following paths.

The issue is that they’re walking all over the Z-axis when pathing. I watch the value in the inspector and it’s all over the place. I don’t know why. The big problem is that eventually they walk behind my background. Since I need collision on my background to pick against, this meant that my characters are no longer selectable.

I’m wondering if there’s a way to restrict pathing to be only on two axes. Right now I have hacked the scripts so that in AStarAI, I make sure the targetPosition Z value is always -1. This doesn’t seem to help that much. I also forcibly reposition the character to z -1 on path ending. This seems to work ok, but I’m still worried about bugs coming from long paths where the character goes behind the background. It would be better to get rid of Z movement completely.

Is that possible?
Thanks!

Hi

At the moment no movement scripts use the XY plane, so you will have to modify those scripts yourself.

You can transform all coordinates from the XZ plane to the XY plane by
pos.y = pos.z;
pos.z = 0;

how exactly do I do that?