How do I Find the closest target

0 favourites
  • 2 posts
From the Asset Store
Aim carefully a shoot the ball at the target to earn scores!
  • 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.

    TIA.

  • Try Construct 3

    Develop games in your browser. Powerful, performant & highly capable.

    Try Now Construct 3 users don't see these ads
  • 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:

    https://www.scirra.com/forum/nearest-instance_t63017

Jump to:
Active Users
There are 1 visitors browsing this topic (0 users and 1 guests)