Is there a way to work with A* in local coordinates? My game area is located at (1000,0,0). When calling seeker.StartPath(startPt, endPt), it considers your parameters world coordinates. Is there any way to globally have the A* component use local coordinate system of my GameArea GameObject?
Current (the +1000 is adding the X coordinate of the gaming area parent container):
hero.GetComponent(Seeker).StartPath(hero.transform.position, Vector3(1653+1000, -541, 1), OnPathComplete);
hero.GetComponent(Seeker).StartPath(hero.transform.position, Vector3(1653, -541, 1), OnPathComplete);
Simple, before you call StartPath, you convert it from global, to local coordinates.
Vector3 globalCoordinate = myGameObjectRoot.transform.TransformPoint ( myLocalCoordinate );
when you get it back, you do the reverse
Vector3 myLocalCoordinate = myGameObjectRoot.transform.InverseTransformPoint ( globalCoordinate );
In the latest version there is an example called “Moving” which shows this, in fact, it uses A* Pathfinding on a moving ship. It uses a recast graph which means the example is only included in the pro version, however the local/global technique itself doesn’t require the pro version.
Also, why don’t you just position the graph at (1000,0,0)?
Also2, make sure to not use too large coordinates, floating point precision gets lower at higher values. I would not recommend using it above coordinate 16000 in any direction (that’s the point where floating point precision starts to get lower than 1/1000 ).
Thanks Aron. I have the TransformPoint & Inverse working, that seems to solve the issue.
Your second response is really what I was going after, but it doesn’t seem to be working. I have tried setting both the GameObject that contains the astarPath script, and the Grid Graph Top-Left to be (1000,0,0), but the StartPath function still uses world coordinates. Here is my Inspector:
I’ve been wondering if there was a way to force the component to use the graph’s coordinate system (which simply overlays the game area at 1000,0,0).
The system will always use world coordinates.
When putting the graph at (1000,0,0) I was thinking that it would play nice with the world coordinates you fed it.
You can always cheat to convert your coordinates into whatever other coordinate system you want to use before sending it to the pathfinding system.
I won’t add anything like this to the core project since very very few people are actually going to use it, and it is easy enough to just add some wrapper code.
(I am still confused about why you are even using local coordinates… but I guess you have your reasons)
Thanks for all your help Aron!