#### Archived

This topic is now archived and is closed to further replies.

# Proximity Testing X & Y Coordinates

This topic is 6001 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Howdy folks, Lets say you have an array which holds the player information, including X & Y coordinates, and the map size is something like 50000 x 50000. What is the best method of determining proximity to another player if you only want to send multiplayer packets when the players are within 300 x 300 of each other, WITHOUT having to do looping checks through the array for each player... THANKS IN ADVANCE!! Kon

##### Share on other sites
How about Grid based optimization ?

ie. Divide the map into 300x300 grid size and each time a player moves, he should check in to an apropiate grid cell. So you''ll only need to check for player proximity between player within each grid cell.

##### Share on other sites
Say that their coords are as follows:

x1, y1 = player 1
x2, y2 = player 2

just check this:

if( abs(x1 - x2) < 300 && abs(y1 - y2) < 300 )
send packet...
else
don´t...

##### Share on other sites

What I''am going to give a shot then is the following, would appreciate comments...

Divide the map into sections(as ZeroBit stated), so a 50000 x 50000, with each section being 500 x 500 would give you 100 x 100 sections. Each section is a array, when a player enters a section they get added to that section array, and taken off the last one they were on. Then in order to check a area, we only need to check the surrounding sections for the users there. Then its just a matter of checking the users x/y coords as Tjoppen mentioned to see if they are indeed within the specified range.

This should be the gist of it... will implement a little differently, but the overall idea should work well I hope! Will find out tonight.

##### Share on other sites
Why split it and do all that moving of people from lists and crap.. it''s not worth it. Just check their distance''s like Tjoppen said.

##### Share on other sites
Oh, and the loop through each player isn''t much over-head (provided you don''t have TONS of players), it''s more over-head to break it into sections. Plus, what if someone is at the very right/top of one section and someone else is at the very left/top of the section next to it.. they are right next to each other, but they are in different sections... so you''d have to also check bounding sections for players, etc,etc which is more work than it''s worth.

Billy

• 17
• 11
• 12
• 9
• 49
• ### Forum Statistics

• Total Topics
631393
• Total Posts
2999757
×