How do I compare distances between multiple instances?

Get help using Construct 2

Post » 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?
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
19
Posts: 1,045
Reputation: 13,977

Post » Sat Jun 13, 2015 10:39 pm

you can use the "nearest/furthest" action in the spawn point object.
B
34
S
6
G
2
Posts: 243
Reputation: 3,040

Post » 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,370

Post » 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.
Follow my progress on Twitter
or in this thread Archer Devlog
B
41
S
18
G
19
Posts: 1,045
Reputation: 13,977

Post » Sun Jun 14, 2015 10:39 am

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


Return to How do I....?

Who is online

Users browsing this forum: tarek2 and 23 guests