# Checking distance between two positions?

## Recommended Posts

for instance...

if player is closer to position1, make them walk there, else if it's position2, make them walk there

##### Share on other sites

position.distance(position)

##### Share on other sites

pos1.distance(pos2)

||

if myPosition#distance(pos1) <= x

//do stuff

else if myPosition#distance(pos2) <= x

//do stuff

Edited by Sinatra
##### Share on other sites

```position.distance(position)
```

```pos1.distance(pos2)

||

if myPosition#distance(pos1) <= x
//do stuff
else if myPosition#distance(pos2) <= x
//do stuff
```

literally just checked the api lol

thx fam

##### Share on other sites

position.distance() will not work properly if you want accurate long distance checks because that's just an application of Pythagora's algorithm and does not take into account plane difference, links or obstacles at all.

map.realDistance(Position position) should take into consideration all the above situations. You could also try walking.webWalk(Position... positions) as that walks to the closest of the given positions since you mentioned you only want to walk.

##### Share on other sites

position.distance() will not work properly if you want accurate long distance checks because that's just an application of Pythagora's algorithm and does not take into account plane difference, links or obstacles at all.

map.realDistance(Position position) should take into consideration all the above situations. You could also try walking.webWalk(Position... positions) as that walks to the closest of the given positions since you mentioned you only want to walk.

However realdistance seems to be off a lot.

I tried using it to find the real closest goblin (like one next to you but behind the fence would actually be further away to run to it)

However it mostly doesn't seem to actually pick the closest one, it looked fairly random

##### Share on other sites

However realdistance seems to be off a lot.

I tried using it to find the real closest goblin (like one next to you but behind the fence would actually be further away to run to it)

However it mostly doesn't seem to actually pick the closest one, it looked fairly random

It seems to be working fine for me but I haven't tested it much. If you don't trust OSBot's realDistance() method you can try implementing A* with collision flags and getting the length of the path and you should get the same result.

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.