Top Down Shooter Multiplayer and Box2D questions

Hey guys! Its me again, the cockdefenders guy!

I’m so thankful for the help I got here the last time, when I managed to make a multiplayer ‘game-prototype’ that mimics valve networking protocol…
This time I’ve got some other questions. Its about a TDS that I’m planning, and I want to make it right. The game will be multiplayer with customizable ships
and Box2D if possible.

hmmm… lets get to the questions then!

  • 1- In my previous networking ‘prototype’ I synchronized about three events per entity, creation, update, deletion. That was done manually with a individual message for each.
    I thought though that I could automate that probably with an interface and a manager, so that I don’t have to code sync code for each new entity. This way I can code only if the
    entity has other atributes that need sync. The question is, has anyone done that before? Any tips or cool desings for those?
    Just to help out understanding, my last design was:
    Client send input changes to server.
    Server simulates everything.
    Each 33ms server sends a snapshot to all clients containing world entities, a timestamp, and removed entities.

  • 2- As I said, I want to use Box2D for nice physics. I’ve got some questions about that. The first question is how I’m I going to code bullets? Does Box2D support bullets?

  • 3- And ho about laser beams? Do I use Box2D to check intersection between line and poligon? Does Box2D have methods for that (handling rotated poligons)?

Hello there! I can’t really answer your first question because i’m not an “expert” with networking.

2 - Yes, Box2D supports bullets. All you have tot do is to set a “isBullet” parameter and Box2D will handle it’s collision as for a bullet.
3 - Yes, Box2D also supports line-polygon intersection. All you have to do is to call a rayCast method and you can handle what to do when a polygon is “hit”.

Using a physics simulation for 2D in a laggy network environment is … ambitious.
You will need to interpolate movements on the client side anyway, and then run Box2d on client and server and then sync it somehow. Good luck…

@65K, I don’t think so…
You can run Box2D only on the server, setting the server to do all the logic, and the client only draw what’s happening on server.

Did you already write a game working that way which shows a fluent movement with realistic physics without stuttering when played over the internet ?
If yes, hats off, otherwise: in theory you can do many things… :wink:

Exactly, theory is one thing. Actually implementing a heavily physics based networking game would be a pain… Why would you ever need box2D for such a simple game? Use either AABBs for simple collision, or use the SAT on client side to test for simple collisions, and only send a packet containing the collision coordinates when need be. Once you have collision detection set up, bullets become rather trivial.

You could even go higher level if you want a library to handle collisions and use Java2D Rectangles.

I could do that, totally… the AABB version… but I think I’m able to get it working with Box2D.
Simulate all physics server side, and on the clients only interpolate.
Using the same principle I’m using now, clients send input and process input locally. Client receive snapshot,
interpolate all entities to their ‘server positions’ (if they are far from the position).
I just don’t get what would be the problem here… everything is simulated on the server. Client only renders and interpolates.

I mean, writing a GRID or QuadTree for broad… that is quite easy.
Collisions would be entirely serverside, handeling and all. The only thing the client do is send input.
I shouldn’t even need a collision message. The server handle states of the entities, even simulates their animations.

Because it is just good … works like a charm, is stable, gives a realistic movement feeling. It takes a good amount of work to redo that.

Then, what would happen during the time a collision is detected by the server until a response travels to the client ?

How would it feel if the player wants to move, but the client has to wait for the server to send its smooth physics acceleration events ?

Don’t get me wrong, I realize box2D Is great. But for a simple TD game? I mean the hardest thing you’ll have to deal with is maybe SAT collisions. You can implement that by yourself and optimize it for a network based game.

A top down shooter doesn’t have to be simple. What is simple anyway ?
A force based physics movement system just gives a more realistic feeling than anything else.
Don’t forget that real programming efforts are always way beyond first estimates.

I didn’t mean top down shooters, OP said he wanted to make a TD game right? I’ve never seen a TD game with any sort of physics, but that’s beyond the point. I was just trying to say that using box2D just for some simple collision detection just seems a bit wasteful, but its OP’s choice!

The topic says “Top down shooter” so just to be clear about the abbreviations:OP mentions TDS, which I guess is short for “Top down shooter” and not “Tower defence”. Just so we´re talking about the same thing here. :slight_smile:

Uhh, top down shooters still need projectile physics, which are fairly complicated if you want ricochet effects. Additionally if he wants lighting he can use box2dlights which uses box2d anyways.

I was assuming OP meant a simple TD game. Not a top down shooter. Shooters are far different. I think everyone is mistaking what I’m trying to say; box2D is very nice but for a TD game it seems overkill… But I never did think of lighting, oops.

TDS = Top Down Shooter.
Isn’t meant to be simple, I wont be coding this alone.

As for server side only collisions, 65k is right. An alternative would be doing client box2d as a low priority ‘visual’ physics while the client waits for the server snapshot. When the snapshot comes, the client then compares the simulations and if necessary, interpolates to server positions.

Damn, I thought TDS meant Tower Defense S… something… sorry!

In that case, yes box2D would be a nice way to go.

I’ll help you, since you are a nice guy.
It could mean Tower Defence Software… or Tower Defence Super! Even Tower Defence Sexy!