1

I am making a MMORPG game for a local competition, I have started working on the server and the problem that I am having is that I want a method to detect Other players that each player see, so that I can send info about players around them to the specific players.

First I thought of attaching a 2d circle object to the Player Object and doing a collision check for each and every player in the Data structure, but This will be very Performance taking, is there a suitable algorithm for this? Please Help me!

Bhanuka Yd
  • 646
  • 8
  • 25

1 Answers1

1

Instead of using a circle and a collision detection library, you can do a manual check using a rectangle, which is nice because your screen and play area is probably rectangular:

int dist = 100;
if (Math.abs(a.x - b.x) < distX && Math.abs(a.y - b.y) < distY) {
    // send player b to player a

You can also do a manual check for the distance between two points, which is just like using a circle but will remove the overhead of your collision detection library.

If your players do not move extremely quickly, you could perform this check every 10 ticks, instead of every tick.

mk.
  • 11,360
  • 6
  • 40
  • 54
  • yh whether I do a circle or a rectangle , I want to know that whether do I have to check each and every player against each and every player before sending them an information. – Bhanuka Yd Mar 13 '15 at 07:46
  • or if I write a good hash function for the data structure to put all colliding players in one hash bucket, will that efficiently solve the problem ? :) – Bhanuka Yd Mar 13 '15 at 08:06
  • You would need a 2d array of buckets; every player between positions x:0-100, y:0-100 would be placed in bucket 0,0 and so on. Then check each player's surrounding buckets. But don't worry about this unless you've measured an actual bottleneck with the rectangle solution - the overhead for doing something more complicated won't be worth it unless you *currently* have 1000s of players. Just use rectangles. – mk. Mar 13 '15 at 14:00