Archived

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

Kon

Proximity Testing X & Y Coordinates

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 this post


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


Link to post
Share on other sites
Thank you for your responses

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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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 this post


Link to post
Share on other sites
Guest Anonymous Poster
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

Share this post


Link to post
Share on other sites