How do I find the distance between two of the same objects?

0 favourites
  • 5 posts
From the Asset Store
This is a Dungeon Master tool & the 1st of 12 Combat Engines from the Building Combat Engines for Browser Games workshop
  • I have a project that makes dungeons.

    Once certain width and height parameters are met they are changed to red.

    Those are now considered Big Rooms.

    Once those Big rooms are created I store the Big Room's UID in an array.

    I need to find the three closest Big Rooms to a selected Big Room, then do that for all the following Big Rooms.

    I don't know how to pick one instance and find the others inside of a for loop using the UID array.

    Then, I want to store the distances in either another array or instance variables with the starting Big Room's UID, UID of the three closest Big Rooms, Then the distance of the three closest Big Rooms.

    What the dungeons look like:

  • One way is to add a family that only has that object type and then use that to pick two separate instances.

    Another way is to pick one of the instances, save the x and y to variables, and then pick the other and do the calculation.

  • Am I going about this the correct way?

    I want to use 2 for loops to go through the array and find all the three shortest distance Big Rooms.

    If it comes across the same UID then skip. If it comes across a UID of 0 then skip.

    Once the slots are populated I want to check each slot too see if they are higher than the next. if they are I want them replaced.

    Here is a screen shot:

  • Here is another crack at it:

    While debugging, my value for Closest_Room_Distance_02/Closest_Room_UID_02 and Closest_Room_Distance_03/Closest_Room_UID_03 are the same:

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • "I need to find the three closest Big Rooms to a selected Big Room, then do that for all the following Big Rooms."

    You can do something like the following. The first event is to select the big rooms. The second event picks only big rooms, loops over each, and then loops over all the other big rooms sorted by distance. The pick by uid condition skips identical big rooms. After that rooms_family will be the the three closest big rooms depending on the loopindex. You can then store the uids any way you like.

    rooms width>32

    rooms height>32

    --- rooms set selected to true

    rooms is selected

    rooms_family is selected

    for each rooms

    X [negated] rooms_family pick by uid rooms.uid

    for each rooms_family ordered by distance(rooms.x,rooms.y,rooms_family.x,rooms_family.y) descending

    --- loopindex = 0

    ------ "1st closest"

    --- loopindex = 1

    ------ "2nd closest"

    --- loopindex = 2

    ------ "3rd closest"

    --- loopindex >2

    ------- stop loop

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