Has anyone have experience implementing collision detection on server side? I am writing a top down 2D multiplayer game. All the players are constantly moving. I want to implement collision detection on the server side so at any time the server will know which player collide with which player and broadcast the result.
The problem is if I use brutal force collision detection to detect collision of every player the resource consumption on the server will be huge (my game updates 60 times a second). I only have experience detecting collisions on client side where I can use broad-phase collision detection such as spatial partitioning. But I have thought about that on server side the server has to know the state of every player so detecting collisions only in a small area doesnt make much sense. So do I have other more efficient algorithm for collision detection on server side?
Here is how I do this:
- I pick a moving sprite from the sprite array
- do a spatial hashing for it and get some nearby sprites
- based on the above method, I loop through the entire sprite array and pick one by one to get some nearby sprites
- I put all the results into a big array and it will store all the sprite for collision detection.
Because I need to send out state information to every moving sprite/entity I have to loop through the entire entity list to do spatial hashing for each one.
I have get answers from gamedev.net forum. What I thought I should be doing was wrong. I don't need to compute all nearby entities for all the entities in one go. All I need to do is loop through the entity list and when I need to send out the nearby bucket list for an entity I do a spatial partitioning for that specific entity. I don't need to do this on every frame. In fact maybe I just need to do it 5 or 10 times per second.