Travelling in isometric paths cross into another path

I am using pathfinding for isometric tower defence game world similar to Cubemen game, featured in your website. I am also using point graph for the units to travel. Since my units are much smaller than the path I have multiple path in the same direction so that the units does not travel one after another.

When i tried this what happen is units sometimes cross into other path going in same direction. I have designed my animations look good when they travel in the isometric path. when they cross into another path the animation looks wrong. If they cross to another path in isometric manner it is OK (green path). But they cross to other paths diagonally it does not look good (blue path).

https://dropbox.com/s/gtegrjqsf4mhcci/paths.png

Can you suggest some method to solve this problem?

Hi

You can set the number of neighbours to four in the grid graph settings, that should solve your problem.

I am using point graph not grid graph.
In grid graph I can see setting called Connections is that the setting?

Our game is 2D game and I have used grid graph before, the problem is I can’t get the grid points to align to both isometric sides. I can only align points to one isometric side.

Is there a way to do this?

Hi

Right, you were using a point graph…
Try getting a grid graph to work by adjusting the Aspect Ratio value in the grid graph settings. It was added specifically for isomeric games.

Hi

Our game is a Unity 2D game. Isometric look is achieved with art work. The camera is orthographic.

As you can see from the image by changing aspect ratio I can only get one side to align with isometric world.

Can you suggest any other workaround for this?

https://dropbox.com/s/z57gg7650g4wtql/paths2.png

Any suggestions on how to get it working?

Hi

It looks like that isometric art is laid out in a 2D plane right in front of the camera (parallel to the clip planes).
Try to place the graph in the 2D plane which the world would have used, if it was not faked using clever art, then rotate it 45 degrees around the Y axis and see if you can get it to work.

Hi
It does not seem to work.

https://dropbox.com/s/d9bttdovcq35chm/path_points.png

If I am using point graph;

As shown in the picture my problem is the system is picking paths like A, B, C. If I can analyze the selected path after on path complete and add a point like D to the list to get a path like A, D, B, and C it will fix the problem.

If the points are correctly set then the direction vector between 2 points can have only 4 possibilities. If I go through the list and calculate direction vectors between adjacent points and if they are different to the possible 4 directions then I know the next point is not in correct position.

I tried the following function and it does work. But is there anyway to improve it?

`
protected virtual void OnPathComplete(Path p)
{
if (!p.error)
{
path = p;
currentWaypoint = 0;

        int iCount                = 1;
        Vector3 currentPoint      = Vector3.zero;
        Vector3 previousPoint     = path.vectorPath[0];
        Vector3 direction         = Vector3.zero;
        Vector3 newPoint          = Vector3.zero;
        float pointDistance       = 1.0f;

       
        while (iCount < path.vectorPath.Count)
        {
            currentPoint          = (Vector3)path.vectorPath[iCount];
            direction             = Vector3.Normalize(currentPoint - previousPoint);

            if ((Mathf.Abs(Mathf.Round(direction.x * 10) / 10.0f) != 0.9f) || (Mathf.Abs(Mathf.Round(direction.y * 10) / 10.0f) != 0.4f))
            {
                // we know the direction is not correct

                if (iCount > 1)
                {
                    newPoint      = previousPoint + Vector3.Normalize(previousPoint - (Vector3)path.vectorPath[iCount-2]) * pointDistance;
                    path.vectorPath.Insert(iCount, newPoint);
                    previousPoint = currentPoint;
                    iCount += 2;
                }
                else
                {
                    previousPoint = currentPoint;
                    iCount++;
                }

            }
            else
            {
                previousPoint     = currentPoint;
                iCount++;
            }
        }

        nextMovePoint             = (Vector3)path.vectorPath[currentWaypoint];
        
    }
}

`

Hi

Is there a way to calculate path by including certain mid points using a point graph? Say go from A to B via point C ?

Hi

Did you set the Connections setting on the grid graph to use only Four connections?

Well, the only way to do that is to do two path requests, A->B, B->C and then merge them together.

I tried with grid graph with 4 connections but I can’t get it to align with both sides as shown in picture. Creeps will move along the paths nicely one side and other paths they move in zigzag pattern.

Is there a way to manually adjust grid points?
https://dropbox.com/s/z57gg7650g4wtql/paths2.png

Got it working.

I had to experiment to find out that you used a camera angle of 30 degrees and a rotation of the world around the Y axis of 45 degrees.
I could actually set it up correct without using the aspect ratio.

Hi

I am still having trouble figuring out how to setup the scene. Please note that my game is a 2D game. I need the nodes in a vertical plane. I have uploaded test project, can you please have a look and advice how to fix this.

https://dropbox.com/s/p4ezgieaaabkfif/PathTest.rar

Sorry for digging up an old thread, but I have a similar issue. I’ve a isometric game where the angle is built into the art, so ideally the scene is set up so the camera is facing directly at the sprites.

I see how aron_granberg set up his scene in those images, but how would the pathfinding work in that instance? How can the grid graph detect collisions given the setup of that scene? Also, wouldn’t the AI characters be in the wrong position when traversing this world?

I know the aspect_ratio parameter was added to work with isometric, but I don’t see how this parameter can be used in this instance, or for that matter how this project can currently be used with a fully 2D isometric game unfortunately :frowning:

@Benzino

In the latest version 3.5.2 (just uploaded) I have added support for a parameter called “isometric angle” which does exactly what you want (I hope).
Try it out and see how it works.

Documentation: http://arongranberg.com/astar/docs/class_pathfinding_1_1_grid_graph.php#aa20f4df5769ec2f2f32b43a05c7dc44c

Oh Wow! That is fantastic and works a treat! Thank you very much!

This is seriously one of the best extensions you can get for Unity :slight_smile:

@Benzino

Great that it works for you!

Hey, btw. If you want to support the package more you can rate the project on the Unity Asset Store and/or write a review for it there :slight_smile:

Cheers,
Aron

@aron_granberg

We are currently using the free version, so cannot rate or review it on the Asset Store. We will be updating to the Pro version in the coming weeks though to take advantage of the multiple threading, so will add a review and rating then :slight_smile: