How do I calculate nearest object pathfinding?

Get help using Construct 2

Post » Mon Sep 08, 2014 8:57 pm

I have been playing around with resource collecting ai, check out the following example.

https://www.dropbox.com/s/ejo9hek1eucof ... .capx?dl=0

The men will find a path to the nearest wood and base but they don't take the walls into account and find the nearest based on a straight line. Is there a simple way to the calculate the length of a path for each target then pick the shortest before moving along it?
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768

Post » Sat Sep 13, 2014 12:58 pm

guess it's pretty difficult then
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768

Post » Sat Sep 13, 2014 12:59 pm

guess it's pretty difficult then
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768

Post » Thu Sep 18, 2014 6:46 am

bump
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768

Post » Thu Sep 18, 2014 1:27 pm

You could just rerun pathfinding on an interval.
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Thu Sep 18, 2014 2:00 pm

that's awesome, thanks for your time. is there any drawbacks from using this method?
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768

Post » Thu Sep 18, 2014 2:24 pm

If you have too many running at the same time, then things might slow down. Just keep an eye on performance
and test as widely as possible, which you should be doing anyway.
ImageImageImage
B
71
S
21
G
231
Posts: 3,691
Reputation: 129,358

Post » Sat Sep 20, 2014 1:10 am

Another interesting idea would be to use
http://en.wikipedia.org/wiki/Dijkstra%27s_algorithm

The idea is to use an array to store the direction to move for every spot to get to the target with the shortest distance. It's just as easy to have more than one target so it's good for many objects that need to find a path to the same set of targets.

So after the array is calculated objects can move to the closest target by just referencing the direction of the square it's currently on.
https://dl.dropboxusercontent.com/u/542 ... eSpot.capx
In the example I made the objects accelerate toward the direction instead of just setting the direction. The result was nice rounded turning.

It caused a stall if I calculated the array all at once, so I adjusted it to only calculate a bit at a time.
B
92
S
32
G
107
Posts: 5,274
Reputation: 69,959

Post » Thu Sep 25, 2014 8:01 am

awesome, thanks for your advice, i'll give the wiki a read
Have retro games for sale? Buy & Sell Retro Games UK
B
9
S
2
Posts: 68
Reputation: 768


Return to How do I....?

Who is online

Users browsing this forum: Exabot [Bot], FacuLNF and 72 guests