Find closest target based on the easiest path not distance.

  • August 6, 2017 at 06:21 #21646
    Adilson
    Participant

    Hi everyone,
    I want to find the closest target based on the path to the target not distance. I’m not sure how do that using Path. I’m using Path, AI, and Steer. So far I can get get the best target based on the score using AI but based on my picture my units always get the target 2 and then after the target 1. Based on the path the target 1 is the best target as they don’t have walk past it to go to the target 2.
    I understand the are choosing it because of they start on the position zero and from there they find the closest based on score.
    How can I pick based on the closest path instead, using AI and Path? Path
    Thanks!

    August 6, 2017 at 06:23 #21650
    Adilson
    Participant

    somehow my image is not showing up using the img tag.. so here is the link to it https://cleverbunny.online/path.png

    August 6, 2017 at 08:23 #21652
    Adilson
    Participant

    This code does almost exactly what I need the issue is that because the path calculation is Async and needs a call back, when the call back is called the Scorer has already returned zer0.
    So, how I do calculate a path without using a callback and of course blocking the game.

    August 6, 2017 at 08:43 #21654
    Adilson
    Participant

    Just to test my theory I put a fixed logic based on the targets previous calculated path and it just does what I want, but it’s not a good solution as I’d have to hardcode all the possible options.
    The code below executes in the way the AI should behave and it will not pass near a target to go to another. Of course if the target is behind wall it will do that as it can’t see.. if they are towers behind the wall, the units will move to the one they have clear path and not the closest one behind walls.

    It has to be a better way of this for sure.. Apex Game Tools guys, is there any solution for this?

    August 6, 2017 at 19:22 #21663
    Geminior
    Keymaster

    There is no way to issue a synchronous path request. The main reason being that a path request may quite some time to finish depending on length etc.

    So there are only really three options I can think of.

    1. You can implement your own synchronous option. Have a look at the path finder implementations under the PathFinding folder.

    2. Have the AI operate on pre-calculated paths. Have a task that calculates paths between all possible destinations at some interval and use these in the AI.

    3. Have the AI set a flag and yield until the path is ready. This might require you to temporarily increase the AI frequency.

    August 7, 2017 at 14:33 #21671
    Adilson
    Participant

    Hi Geminior,
    I got the sync option working, the issue I’m facing now, sorry my brain is kinda burn for the day, is that the longest path(higher path cost) is selected first.
    I’m using the AI from the Survival tutorial as a guide. So, I’ve a Composite Action with the code from the topic above #21652, except that it now runs synchronously.
    How can I convert the higher cost to low score and low cost to higher score? or use a custom Qualifier, or Scorer, etc.
    I have tried a few things but I can’t get it working.
    Thanks in advance.. I can see that I’m quite there but it’s missing something very small to do..

    August 7, 2017 at 14:46 #21673
    Geminior
    Keymaster

    Well I am not sure what the exact use case is here, but either you simply select the desired path in the action itself and pass it on to the agent.
    Otherwise, if you want to AI to evaluate the potential paths, follow the action of calculating the potential paths with a selector that selects among them. Scoring low cost high is trivial, just multiply by -1, or if you like, subtract from a large number, e.g. 10000 – cost.
    You can also use a selector that selects the lowest score rather than the highest.

    August 8, 2017 at 12:55 #21681
    Adilson
    Participant

    Thanks Geminior!
    I was after something very difficult and I forgot about just multiplying to -1 would do the trick.
    So, as per my posts above I was able to get the path calculated synchronously and multiplying to -1, it works as I expect.
    The target is selected based on the path, the shortest is the first one in the waypoint, even if it’s behind a wall.
    However, my FPS drops down from 250FPS to 15FPS.. :-) not good.. So, unless I’m doing it wrongly, it’s not usable..
    I guess I’ve to keep trying and if I can’t improve FPS give up on the sync approach.
    Thanks a lot for your help so far!

You must be logged in to reply to this topic.