Check for nearby instances?

0 favourites
  • 3 posts
  • Im creating a certain number of objects in randomized locations now I want to be able to loop thru all those instances and check for nearby instances in specific locations (above, below, upper left, etc) to perform specific actions

    How exactly would I go about checking in these directions around a given object (its picked via loopindex in a for each)?

  • You want to check if each object has another one close by? I did this recently by adding each object to an array, like this:

    Start of layout

    + For each object

    -> Set value at int(object.x/32)*32, int(object.y/32)*32 to 1

    Then you loop through each array element and check if the position above, below, etc equals 1, that means there's an object immediately near it

    It was quite difficult to work with it, you will probably need to save the UID of the object to a similar array to use it later... unfortunately I don't have the project anymore so I'm not entirely sure how I did it

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • I figured it out for my needs. What I did was make 1d array and when I created the blocks I put their x,y in as the value like Block.X&"|"&Block.Y then I For Each'd thru the blocks and checked if the array contained a value for the directions I needed to check. Works great

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