How do I target nearest sprite with the same type of sprite?

Get help using Construct 2

Post » Sat Feb 21, 2015 4:09 pm

I'm trying to do some simple enemy Ai, and I want each enemy sprite to have a "Target" which is the nearest sprite that it should follow.
But I'm having some problems figuring out how to decide each enemies nearest target.

Basically I just want to know what enemy is nearest to another enemy, taking walls into account.
I've included a really stupid example of what I want, and that shows that my idea of how to do it doesn't work hehe.

Thanks for any help!
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 5
Reputation: 554

Post » Sat Feb 21, 2015 5:04 pm

Use a Family to make working on two of the same object type easier. Also, be sure to exclude the sprites 'self' or the Pick nearest by location will always pick itself!
You do not have the required permissions to view the files attached to this post.
ImageImageImage
B
71
S
19
G
180
Posts: 3,479
Reputation: 103,179

Post » Sat Feb 21, 2015 5:16 pm

Ah thank you, that makes sense!
But your example seems to only pick the target for one of the enemies.
I'd like them all to have a target.

Image
B
9
S
1
Posts: 5
Reputation: 554

Post » Sat Feb 21, 2015 5:42 pm

Oops, drag "Has LOS" before "Pick nearest"
ImageImageImage
B
71
S
19
G
180
Posts: 3,479
Reputation: 103,179

Post » Sun Feb 22, 2015 12:48 am

Thank you so much, your example works.
But I'm still having problems figuring out exactly how to use this heh.

Is the loop the actual target, or is the loop for the sprite that gets the target? I'm confused...
Last edited by Hezkore on Mon Feb 23, 2015 9:19 am, edited 1 time in total.
B
9
S
1
Posts: 5
Reputation: 554

Post » Mon Feb 23, 2015 9:19 am

This is what I ended up with, what could I improve on this?
You do not have the required permissions to view the files attached to this post.
B
9
S
1
Posts: 5
Reputation: 554


Return to How do I....?

Who is online

Users browsing this forum: OddConfection, senna68, smlyldz and 10 guests