I’m trying to revive a long-forgotten project.
Basically, each player in this game will control an object that can be represented as a circle in 2D. The players will be moving around a playing area and they can bounce off each other with (hopefully) some semblance of realism. Having studied physics in high school this past year (woo hoo!) I can pretty confidently say this is a case of an inelastic collision, since /some/ energy will be lost. But, for simplicity’s sake, I’ll probably simulate it as an elastic collision.
I’ve heard networked physics is really, really hard, but I’m sure there are some shortcuts I can take because it’s circles in 2D?!
I guess my question is 2 parts:
- Since kinetic energy and momentum are both conserved in an elastic collision, the sum of the momenta of the 2 objects involved in the collision will be the same before and after the collision. The equation we were given to solve elastic collisions is:
m1v1i + m2v2i = m1v1f + m2v2f
In my game, for now, I’m assuming all objects have a mass of 1. So,
v1i + v2i = v1f + v2f
Solving for v1f and v2f,
v1f = v1i + v2i - v2f
v2f = v1i + v2i - v1f
(where v1 and v2 are <x, y> velocities, ‘i’ means initial, and ‘f’ means final)
Each solution depends on the other… I need more information? What other information? In all the types of problems we were given to solve in school, they always gave us one of the final velocities.
- What is the best way to communicate player physics updates to all the rest of the clients?
The old implementation just fired off packets from the client to the server every 30 milliseconds with the player’s new position, and the server would then spam everybody else with the new data. Needless to say, this didn’t work too well.
How hard can a good implementation be?
Sorry this post is pretty scatterbrained, it’s late here.