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
14
S
4
G
4
Posts: 133
Reputation: 3,150

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
44
S
13
G
7
Posts: 338
Reputation: 10,379

Post » Wed Apr 10, 2013 11:14 pm

@zatyka amazing solution! I'll save it for future purposes, hehe
ImageImageImageImageImageImage
B
93
S
20
G
12
Posts: 1,211
Reputation: 18,480

Post » Wed Apr 10, 2013 11:45 pm

@zatyka A slightly simpler way that doesn't need an array: pick4nearest.capx
B
54
S
28
G
18
Posts: 1,520
Reputation: 25,020

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
14
S
4
G
4
Posts: 133
Reputation: 3,150

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
44
S
13
G
7
Posts: 338
Reputation: 10,379


Return to How do I....?

Who is online

Users browsing this forum: Scofano and 22 guests