Help with nearest object in a family...

Get help using Construct 2

Post » Wed Feb 26, 2014 6:41 pm

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:
Image

attemp1:
Image

2:
Image
B
38
S
11
G
1
Posts: 203
Reputation: 4,473

Post » Wed Feb 26, 2014 7:11 pm

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?
B
44
S
11
G
2
Posts: 1,182
Reputation: 6,848

Post » Wed Feb 26, 2014 7:28 pm

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 :
nearestInFamily.capx


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 :)
You do not have the required permissions to view the files attached to this post.
B
17
S
8
G
4
Posts: 473
Reputation: 6,191

Post » Thu Feb 27, 2014 6:04 pm

Thanks for the replies. Looking at the example I got a good understanding and managed what I was after =)

Image
B
38
S
11
G
1
Posts: 203
Reputation: 4,473


Return to How do I....?

Who is online

Users browsing this forum: brunopalermo, Yahoo [Bot] and 30 guests