Sign in to follow this  
Followers 0
Seagul

distance between moving object and 2 targets

4 posts in this topic

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

post-7227-12570126389734_thumb.gif

Share this post


Link to post
Share on other sites



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

Share this post


Link to post
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
    call("yada")
    EndSelect

Share this post


Link to post
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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0