Help with nearest object in a family...

0 favourites
  • 4 posts
From the Asset Store
Game with complete Source-Code (Construct 3 / .c3p) + HTML5 Exported.
  • Hi,

    I am trying to work out which sprite is nearest to a certain object at any given time and then store the co-ordinates of that sprite. Currently I have tried two options as below. The first one it will give the co ordinates of the last sprite moving. The other attempt only stores the first sprite.

    All of the 8 sprites I want to check are bowls and each one is its own separate sprite, not a clone etc..

    They are all added to a family together called collision including the small yellow jack. I'm sure its probably easy when you know how!

    My aim is to work out which bowl is closest to the jack so the computer AI can work out if to bowl above or bellow the middle block.

    Any help would be appreciated!!

    ingame:

    attemp1:

    2:

  • Not sure if it will solve you problem, but it seems weird that the Collision X > 1301 is below Jack Pick nearest ..... As I assume you want to pick the nearest jack to the collisionFamily that are between these values?

  • Hey,

    Picking the nearest object in the same family can be confusing, as you have sometimes a hard time finding what element you are currently manipulating.

    I did an example : [attachment=0:fadaxu3a][/attachment:fadaxu3a]

    In this example, I find the nearest element in the same family for each element of the family. To illustrate it, I then make each ball move to this nearest ball.

    You can drag an drop balls to test this, and hit the button to trigger the calculation an movement.

    Events are heavily commented for complete explanation on the method.

    I hope this was what you needed

  • Try Construct 3

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

    Try Now Construct 3 users don't see these ads
  • Thanks for the replies. Looking at the example I got a good understanding and managed what I was after =)

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