I’m doing a game using 2D Toolkit that uses the XY axis instead of the XZ axis. Since all of the scripts make use of the XZ axis, I’ve been trying to modify these to use XY, specifically AIPath.cs. After a lot of fiddling, I’m finding it very difficult to get this working properly. Has anyone attempted this? It seems like this should be a very common issue, but I haven’t been able to find a solution. If anyone has one, please email me at madguy88@hotmail.com (yeah, ancient email address) – If I find a working solution I’ll post it to a Dropbox for others to check out.
I am not 100% sure, but I don’t think you can use this tool to do XY plane path finding. I don’t think navmesh graph will even generate if you use XY plane. but having said that, I don’t know if there is way to generate navmesh in XZ plane and then rotate them later… I too, been looking for XY plane solution but not that many supports it and few that I found doesn’t give you enough “features” to be really useful in production.
It is really shame (and lame) that Unity tries to support 2D stuff, but no navmesh solution for it. I have been asking Unity guys about this, and everytime I ask, they just mumbles like… “ugh…” “yeah… humm” or like “we have best guy working on 2D stuff” (what is that even supposed to mean.?)
Not every 2D game is side view platformer. Really…
You can use A* to generate paths on the XY axis-- I’m able to do it myself. My only issue is with the AIPath.cs, which is a pretty nice script for getting the gameObject doing the pathing to move exactly as you want, that unfortunately happens to be tailor-made for XZ. I’ve looked around these forums for a solution, and it seems like the script can definitely be modified to suit my needs. I’m just not sure of exactly what parts need to be modified, and how to do it.
Well, I didn’t know if it was possible to create navmesh uing XY plane and make them 100% vertical…
Hi
Grid graphs and point graphs do not assume any particular up direction, they can be rotated however you want. The recast graph and the navmesh graph assumes that world up = graph up, and while the navmesh graph can often be used on the XY plane, I would not recommend it since many other things (like the funnel modifier used on navmesh graphs) do not support the XY plane.
I really should write a XY controller for the next update…
The AIPath script can be modified, essentially replace .z with .y and vice versa.
Will recast graph be able to generate navmesh in XY plane? If not , sadly it won’t work for me.
Sorry. While it would be possible to generate a navmesh in the XY plane, there are a HUGE load of other functions that depend on the XZ plane being used, so it would likely not work anyway.
However, I workaround is possible. There is a scene called “Moving” which shows how some cheating can be used to enable pathfinding on a moving object, it basically translates from the object space to the graph space and vice versa. This can be used almost out of the box for a 2D scene.
The movement script will still need to be changed however.
The AIPath script can be modified, essentially replace .z with .y and vice versa.
Doing JUST this doesn’t seem to work-- more modifications are required. I think some of the code in CalculateVelocity may require additional changes (the “Vector3 forward” reference for example). I’ve been fiddling around with it, but sadly movement isn’t really my strong suit
I swapped the Y and Z, but then I didn’t want my sprite rotating to face the target. So I set the “Turning Speed” setting to 0, but then the AI doesn’t move.
After looking through the code, I believe toward the bottom of CalculateVelocity(), the rotation is taken into account so the AI moves in the direction it’s facing. I didn’t want that, so I changed this line:
Vector3 forward = tr.forward;
into this:
Vector3 forward = dir; // dir is the direction to the target
And now my AI moves in 2d!
Not an elegant solution, but works for now.