How do I Find the closest target

Get help using Construct 2

Post » Thu Nov 13, 2014 7:12 pm

Hi everyone!

I would like to find out how to find the closest X for pathfinding.

I have a player and a target, the target has an instance variable. On the layout I have 2 instances of the target.
What I want to do is get the player to move to the closest instance.

If I do a find path on the player, it seems to always move to the first instance or target regardless of how close it is.

So I flipped it around.

In order to do that I do a for each "Target", find path back to player. Then on the path found event of target, I save the number of nodes on each instance of the target.

Then I do a Find lowest instance of target using the instance variable and thus I can get the target with lowest nodes . I then pass that reference through to find path on player .

However sound this may seem, it doesn't work.

If there is another way to do it please feel free to shout it out.

Posts: 10
Reputation: 285

Post » Thu Nov 13, 2014 7:33 pm

Give this a read, it may give you some insight into how something so simple is not so much so. It does offer some good options though you might be able to use:
Check out my completed games on the Arcade! Capt. Doe Save the Universe! & Clicker Wizard!
Posts: 649
Reputation: 10,253

Return to How do I....?

Who is online

Users browsing this forum: 64kStudios, leak123, Luvkraft, Metathronos and 20 guests