How do I find the distance to closest 'like' object

0 favourites
  • 5 posts
From the Asset Store
Use this game pack to create your own game, modify the existing game or simply take a look and see how it was made.
  • i have been able to successfully measure the closest distance to non similar objects.. can anyone point me on the right path to find the nearest similar object's distance?

    For instance you have 5 eggs randomly on the screen and you want to have an instance variable for each egg that is aware of the nearest other egg. How could I do that?

    distance does not play nice with 'this.x,this.y" In my example CAPX it always chooses itself as the closest.

    Heuristic that worked for non-similar objects

    Not working: (SEE CAPX)

  • You need to store the location in variables, mark it as "selected" or something with a boolean, then in the next sub-event's conditions pick all objects of the same type*, then exclude the selected object and after that add a pick closest to X,Y condition.

    Please see capx as an example:

    https://www.dropbox.com/s/z1df71tscepzr ... .capx?dl=1

    *remember every condition picks only out of the objects exluded by the conditions before/above it, you need to make sure you are selecting out of all objects again hence why you need pick all which resets it to all, then you narrow it down to all but the selected one.

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • This is a great example, but I need to be able to have each object know the closest other object without the "is selected." Do you know of any way to do that?

    Thanks for posting this.

  • This is a great example, but I need to be able to have each object know the closest other object without the "is selected." Do you know of any way to do that?

    Thanks for posting this.

    It is the same. Just a iteration more (starting from the selected one), in a nested loop. But, lets mask 'the selecteded one' so you are not able to find it.

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

  • thank you. pretty nice guys

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