Pick Nearest 4 instances

Get help using Construct 2

Post » Wed Apr 10, 2013 8:18 pm

Hello, how can I use Pick Nearest to get multiple objects.

This is the case:

There are spawning points around the map and I want them to spawn one enemy each one when the player is passing by them.

How can I do that??

Thank you.
Image
B
15
S
4
G
4
Posts: 134
Reputation: 3,177

Post » Wed Apr 10, 2013 10:36 pm

I think you're better off avoiding the "Pick Nearest" condition in this scenario. You could probably somehow use it in conjunction with the "pick all" condition to find the nearest 4, but that seems like a really ugly solution to me.

There could possibly be a more elegant way to do this, but this is what I came up with:

Demo
Annotated Capx

It stores the distance between the hero and each enemy in an array, sorts the array to find the 4 with the shortest distance, and changes their frame.zatyka2013-04-10 22:55:17
B
63
S
19
G
8
Posts: 341
Reputation: 12,130

Post » Wed Apr 10, 2013 11:14 pm

@zatyka amazing solution! I'll save it for future purposes, hehe
Image
B
108
S
24
G
18
Posts: 1,372
Reputation: 22,817

Post » Wed Apr 10, 2013 11:45 pm

@zatyka A slightly simpler way that doesn't need an array: pick4nearest.capx
B
55
S
29
G
19
Posts: 1,520
Reputation: 25,650

Post » Thu Apr 11, 2013 12:02 am

You know what was simpler?, I asigned the turret behavior to the spawners and asigned the player as target, then I just listen for the "onTargetAdquired" to trigger and I spawn enemies.

This way everytime the player gets on range it is adquired by the spawners and they trigger.
Image
B
15
S
4
G
4
Posts: 134
Reputation: 3,177

Post » Thu Apr 11, 2013 12:27 am

@ramones

Awesome! I hadn't considered ordering a loop by a calculated expression.zatyka2013-04-11 00:41:41
B
63
S
19
G
8
Posts: 341
Reputation: 12,130


Return to How do I....?

Who is online

Users browsing this forum: beohs, brunopalermo and 12 guests