(BUG) Wrong path is generated when start and end are too close


#1

I’m using a grid grah. I only placed two points since I’m just experimenting with it and I only have a platforme and I use the Seeker script with the following parameters.

When the start and end point or far enough, the generated path is perfect (two vectors: the start point and the end point)

Now, the bug comes in if I move the end to close to the start:

The log you see is:
for(int i = 0; i < m_path.vectorPath.Count; i++)
{
Debug.Log(m_path.vectorPath[i].x + " : " + m_path.vectorPath[i].y);
}
Debug.Log("-----------------------------------------------------");

Has you can see, an extra vector is created and instead of a simple path, that should just be the start and the end point, a path that doesn’t make sense is generated! Plus, this would make my character walk needlessly to the left to just than come back to the right.


#2

Hi

Do you think you could show me the graph that you are using (all the nodes in it)? I notice that you have a hidden grid graph as well, could that be causing any issues (if the character at some point finds that it is closer to the grid graph than the point graph, it might start to use the grid graph instead)?

Also. It looks like you have the AstarPath object attached to your character, that’s not what you should do. There should only be a single AstarPath component in the scene, usually attached to some global object in the scene. See https://arongranberg.com/astar/docs/getstarted.php


#3

First of, thank you for your reply :slight_smile:

Here is the graph I use (it’s crazy simple, but it’s just because I’m playing around with the A* pathfinding project)

I don’t have an AstarPath on my character. I just locked the inspector window before selecting my character, so that you could see both the setting of my A* and the settings of the Seeker script (sorry if the picture confused you). I also tried to delete the grid graph, but the problem still happens.

On a last note, I keept playing with it and I found an other bug: I hadded a third point and did kind of a triangle shapped path (with one side not connecting). I think you will see the issue with this picture:

If this doesn`t help, here is the Github of my project:


#4

Hi

Which version are you using? It looks like it might be an older one. I know the point graph has had a few bugs in earlier versions related to finding the closest point in point graphs.


#5

Hi

Version 4.2.4 (2018-12-03)


#6

Hi

I’m not sure what could be going wrong here. Perhaps you could share a simple test scene with me and I could have a look?


#7

I already did.

Here is the Git Hub I’m working on https://github.com/ertsnom99/plateformer.
I’m using Unity 2018.2.8f1. Try the scene named BossFight and just jump to the middle platformer and you will clearly see the issue

Also, here is an other capture of the issue:


#8

from just looking at your picture i don’t see much use for path finding and i believe you would make benefit more from the use of physics.

the way your nodes are spaced out maybe your picking a starting node that isnt actually somewhere the fox would be standing.
consider using a grid graph if the fox can move independently of the pathing script


#9

On the contrary, the point graph is perfect for my needs (considering this is a prototype). Plus, I don’t get what you mean by “the use of physics”… Do you mean moving the character? Because that is handeled separetly (there is a complete seperation of moving (done by my scripts) and finding the path that the character should take (done by Pathfinding project))

A grid graph is a bad idea (for an AI that can jump from a palteforme to an other (it’s way better for flying ennemis)), because it is most likely to not do strait line when going up to a plateforme, which would make the process of reaching the target needlessly to complicated. Strait lines are perfect since the x and y component can be use to decide to either jump (and how much) or just let the character fall of the paltform.

There are other ways to make pathfinding for AI for platformer, but they would take to much time for just a prototype.

The real issue here is that it just seems to have a bug. It should simply find the closest position along the path and start from there, but, has you can see, it doesn’t. Either way, someone else was bound to have the same problem, so better fixe it now! :slight_smile:


#10

what i assume is happening is that say the fox has a node to the left and the right of him, you want him to move right but the left node is closer to him, so he starts his path moving to the left node then goes to the right because that would put him back on the path which he wasn’t on because he moves independently , you could try populating the map with more path nodes, if thoes nodes you have set up are special locations that a unit must stand you could set something up that would cause a a path to go to thoes specific locations. instead of having them as the only locations


#11

The problem is that there IS an option that tells him to start the path at the close point on the path AND that point doesn`t have to by one point, it can be any position along a link. If it worked correctly, then everything would be perfect, but it clearly doesn’t start at the right place. My AI doesn’t have to be preceasly on the path, just close enough. Bottom point, it 's a bug that should be fix.


#12

Hi

Just to make sure. Are all your point graph nodes placed on (roughly) the same z coordinate? Or do they vary a lot?


#13

They are all exactly at z = 0


#14

Hi

I could not replicate the issue anymore after I removed your PathNeedsFix method which seems to remove nodes from the path for unknown reasons sometimes.


#15

I will try it on my side to


#16

Indeed, it was my code the problem. I hadded this code because I had an other problem with the path, but when I removed my code, I guess this problem was fixed during the last update, since it doesn’t look like it’s there anymore.

Thanks alot for your help! :slight_smile:


#17

I have unfortunate news. I found an other problem and this time, my code isn’t the cause of it! I’m not sure how to explain it, but the wrong path is generated. I added two picture.

The first one shows the path being correctly calculated. The second picture is what happen when I just move a little my character (the wrong path).

Clearly, the path generated is not good and I made sure to check without my code that changes the path (it doesn’t apply in this situation anyway).

The link to my git up (see previews replies) is still working. To reproduce the bug, select “Jumping Paltformer AI” in the Hierarchy tab and untick “Platformer Movement” (to prevent him from moving). Then, just move around the AI with the move tool. The project is in Unity 2018.2.8f1.

I also did a video (bug starts around 24 secondes):

Hope it helps


#18

you’re recalculating the path while hes moving and not waiting for his path to finish before starting a new one.
and ill reiterate you’re using the system backwards, you’re using nodes like waypoints, the path is suppose to find the nodes between waypoints.


#19

I have no choice to recalculate the path (4 time by seconds) since my AI is trying to follow a character (the character is moving). Plus, in this case, my path DOES have time to finish before recalculating it and it doesn’t have anything to do with this issue. I say this for two reasons:

  1. I get a log message telling me that the Path was completed without any problems

  2. Just to be sure, I tweaked my code so that it will only calculate ONE path at the start (in case the confirmation logs were wrong somehow). I made sure that my AI is at the same spot has the one showed in the video and that he isn’t moving AT ALL. The wrong path still get generated and since I only genereted the path ONCE, I think you can agree that the update rate AND the movement has nothing to do with this issue.

Also, I’m not using the nodes like waypoints. My AI is using the path generated the figure out how to move to reach it’s destination (actually, it’s figuring out it’s controls, because controls and movement are completly seperated, but that’s not what is important here).

Finally, even if I was using the system backwards, that is not what this issue is about. I get that you’re trying to help me, but what I need help with is the path not being correctly generated in this specific case scenario.

Again, thanks for your help, but I think you’re not looking in the right place.


#20

you want it to use the top path. but the path from the ledge is shorter than the path from the left of the ledge.
you are creating a new path before the fox has had time to reach the next platform, its taking the shorter of the two paths, although both paths look equal distance. its just prefers one of the two equal distance paths over the other…