# How do I compare distances between multiple instances?

Get help using Construct 2

### » Sat Jun 13, 2015 10:28 pm

I have a map with 9 spawnpoints, and 3 enemies. When i die i want to spawn at any of those points based on the distance to those enemies. Preferably the safest one furthest away from any of these. I know how to get the distance between a spawnpoint and an enemy, but only for one instance of each.

for example.

for each spawnpoint
distance(spawnpoint.x, spawnpoint.y, enemy.x, enemy.y) - will only get me the distance to one if the enemies. or is there any way to specify which of the enemy instances i want the distance to?

how do i get the distance between all of them?
or in this thread Archer Devlog
B
44
S
20
G
19
Posts: 1,091
Reputation: 14,376

### » Sat Jun 13, 2015 10:39 pm

you can use the "nearest/furthest" action in the spawn point object.
B
42
S
7
G
2
Posts: 263
Reputation: 3,380

### » Sun Jun 14, 2015 5:38 am

Locale variable "CurrentBiggestDistance"
Locale variable "MostFarUID"

OnDeath
------for each spawnpoint
-------------for each enemy
------------------------distance(spawnpoint.x, spawnpoint.y, enemy.x, enemy.y) > CurrentBiggestDistance : Set CurrentBiggestDistance to distance(spawnpoint.x, spawnpoint.y, enemy.x, enemy.y) AND set MostFarUID to enemy.UID
-------Pick spawnpoint UID= MostFarUID : Spawn Player
-------[No condition] : Set CurrentBiggestDistance to 0 AND Set MostFarUID to -1

gl!
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,375

### » Sun Jun 14, 2015 10:35 am

ikke2902 wrote:Locale variable "CurrentBiggestDistance"
Locale variable "MostFarUID"

OnDeath
------for each spawnpoint
-------------for each enemy
------------------------distance(spawnpoint.x, spawnpoint.y, enemy.x, enemy.y) > CurrentBiggestDistance : Set CurrentBiggestDistance to distance(spawnpoint.x, spawnpoint.y, enemy.x, enemy.y) AND set MostFarUID to enemy.UID
-------Pick spawnpoint UID= MostFarUID : Spawn Player
-------[No condition] : Set CurrentBiggestDistance to 0 AND Set MostFarUID to -1

gl!

mrlight234 wrote:you can use the "nearest/furthest" action in the spawn point object.

Thanks both. i managed to make crossover between both solutions, marking any spawnpoint with no enemies within a range as safe, then spawning at a random "safe" spawnpoint.
or in this thread Archer Devlog
B
44
S
20
G
19
Posts: 1,091
Reputation: 14,376

### » Sun Jun 14, 2015 10:39 am

You are welcome
It's time for me to return the favor :)
B
32
S
9
G
9
Posts: 132
Reputation: 5,375