Support Forum

2D path not accurate while moving

Hi @aron_granberg

I’m having an issue regarding path is not getting followed properly or you can say path gets changed for a friction of second.

I’m creating 2D game demo with top down approach. Everything works pretty well and object is following it path. I’m using line renderer to show the path of object with the help of new method GetRemainingPath introduced in last version.

Start end modified is set to NODE CONNECTION and end modifier is set to NODE CENTER. Pick next point is also set to 0.7. No matter what I select as the start end modifier, path the object is following is changed at certain point.

For the reference, I’m attaching screenshots which will help you to understand the scenario.

  1. Showing proper path
    Issue-1

  2. When object reaches to some point it will show the different path for a second but it won’t follow this path. It will continue to move on 1st image path.
    Issue-2

  3. Even at the end of path it shows different path.
    Issue-3

It will be really great if you can help me and thanks for the plugin :slight_smile:

Thank you.

Hi

What movement script are you using?

Do you think you could post a video of this issue?

Hi,

I’m using AIPath with 2D as settings. I’m attaching a video for reference.

Video reference

  1. Around 0.12 seconds you will able to see that when I click to another point it shows wrong path for friction of second and then correct path.

  2. In rest of the video you will be able to see the incorrect line on which the player is following.

Thank you for the quick response :slight_smile:

Hi

At around 0:12 I see that it first calculates a path which looks correct, then a fraction of a second later when it has moved a bit further it recalculates the path and now it is faster to go around the wall in the middle on the other side, so it looks like it is flickering a bit.

You can reduce this flickering by only recalculating the path when you explicitly change the target.

Set AIPath -> repath rate to something reasonably large (maybe 2 seconds) or disable can search altogether. Right now you have it set to 0 which will make it recalculate the path every single frame (or at least as often as possible).

Then when you set the target call ai.SearchPath as well to recalculate the path immediately.

ai.destination = something;
ai.SearchPath();

Note that the AIPath script has inertia, so it cannot not change direction and follow a new path immediately. You can use the AILerp script instead if you want it to follow the path without any inertia.
See https://arongranberg.com/astar/docs/movementscripts.html
and https://arongranberg.com/astar/docs/ailerp.html