Finding shortest distance to object

This forum is currently in read-only mode.
From the Asset Store
This is a single chapter from the "Construct Starter Kit Collection". It is the Student Workbook for its Workshop.
  • For most of the day, I've been killing myself trying to figure out how to measure the shortest distance between two objects and then moving one of the objects to the other. For example, a man gets hungry. There are several break rooms in his workplace and Construct can't really decide which he should move to, so it ends up picking the one so far away that he starves to death on the way.

  • Does this help?

    Just scroll down a bit and click on deadeyes link.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Almost worked, but if I have several instances of scientists that suddenly get hungry at the same time they all pick the same table. Still, better than nothing. I suppose it'd work pretty well as long as not all the scientists are created at the same time.



    Actually nevermind, seems it only finds the closest table to the first scientist to spawn.

  • Well, if you can't find a solution, you could post your .cap and I see what I can do. So I get a better overview of all.

  • FYI, there is a system expression: Distance(x1, y1, x2, y2)

  • Murkat, try to reverse your picking.

    If you are picking table vs. scientist, with the scientist as the condition... try making the table the condition instead. Get what I mean?

    That will probably fix your issue :)


  • Woo, fixed it with a For Each loop. I'm a bit concerned that this might slow the game down in the future, but testing it with somewhere between 50-100 instances seemed to work pretty well, and I doubt I'll need more than that.

    Man that felt good.


    SoldjahBoy Not quite sure what you mean, but doing it like this seemed to fix the problem.

    <img src="" border="0" />

    If there's a better way of doing it(I literally just found out how sub-events work today), I'd very much appreciate the input. I can already tell this method of doing it is less than optimal, but it's the only one that worked, so yeah.

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