# distance between moving object and 2 targets

## Recommended Posts

How do I go about calculating something like so and choosing shortest distance from green dot to yellow dot.

##### Share on other sites

`\$distance=sqrt( (abs(\$x_yellow-\$x_green))^2+(abs(\$y_yellow-\$y_green))^2)  ;should be old pythagoras^^`

##### Share on other sites

So something like this but how would I tell it to store multiple targets so I would be able to pick one under my case. like click target a. click target b.

```\$target = _ImageSearchArea("target.gif", 1, \$x1, \$y1, \$x2, \$y2, \$a1, \$b1, 35)
\$shiptarget = _ImageSearchArea("ship.gif", 1, \$x1, \$y1, \$x2, \$y2, \$sx1, \$sy1, 35)
\$distance = Sqrt((Abs(\$a1 - \$sx1)) ^ 2 + (Abs(\$b1 - \$sy1)) ^ 2)
Select
Case \$distance >= 800
sleep (15000)
Case \$distance >= 400
sleep(7500)
Case Else
EndSelect```

##### Share on other sites

So something like this but how would I tell it to store multiple targets

1. while-loop,  detect the positions of all possible targets

2. store these positions into an \$array[\$target_type][\$posx;\$posy]   ;maybe you do not have to do so if you have only one target_type

3. in a for/to-loop, check the distance between ship and all targets (which were stored in the array)

4. if the distance between the ship and one of the targets < critical_distance then do something depends of target_type

5. wend  ;goto 1

## Create an account

Register a new account

×

• Wiki

• Back

• Git