How do I make my AI controlled sprites (visitors) move to the closest sprite (bar etc.)?

0 favourites
  • 6 posts
From the Asset Store
Move Block
$10 USD
Captivating puzzle game. With challenging gameplay, this game will keep you very engaged.
  • Hello!

    I'am still pretty new to construct so sorry if the answer is obvious to you guys but I have been searching my ass off trying to find an answer. I have read the tutorials and I found alot of people who have been asking almost the same kind of question but I can't really work it out in my own project.. I just don't seem to understand it :(

    In my project I have got a lot of sprites that are the visitors of a festival, these visitors have got instance variables like thirst, hunger, toilet. When these variables reach <= 5 they go to the toilet, bar or where ever they need to go to get this variable replenished. This works great, only problem is that they do not go to the nearest but to the first one created.

    I have tried to use the pick nearest option, but they still go to the first placed(wich is the furthest)..

    Hope you guys can help me!


  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Your events should look something like this:

    Every 1 second
    Character Pathfinding not moving
    Character hunger>=5
    For each Character
     Bar pick nearest to Character
    	Character find path to Bar
    Character on path found 
    	Character move along the path

    If this doesn't help, please post your project file or code screenshot.

  • Thank you for the quick response! I will try this as soon I get home from work!

  • dop2000 This is how I have tried to make it work, but it doesn't. Would you please take a look at the code in the capx? Thanks in advance!

  • It seems to work fine for me. If you create several stage sprites, you will see that bezoerkers are moving to the nearest stage.

    What you need to do is remove all "Trigger once" conditions from all events in your code! Don't add this condition to "For each" loops, or when dealing with multiple object instances. It can cause all kinds of bugs when used incorrectly.

  • YESS!!! Thank you so much!!

    It works now :)

    You are awesome!

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