Hello all. I've been working on an online action platform game lately and I'm running into an issue that has me stumped.
The game uses Box2D mainly for player collisions and movement. Players can not affect each other physically. Right now there are no interactions between two dynamic objects (there will be eventually, but I have a few ideas on how to handle it). The networking system I've devised to prevent speed and teleport hacking involves making it so both the client and server can rewind specific instances and replay them to the current simulation point with new input. I do this by saving the x, y, linear velocity, and input variables of each player for a set period of time. Then, when I need to rewind, I deactivate all dynamic objects except the one I'm trying to simulate again. The rest don't need to be simulated again because they don't affect each other. The system then gets stepped through it's paces the correct number of times and in theory the object should now be in the correct position. This works great, most of the time. I'm noticed though that under certain circumstances the client and server disagree on the final position and the client's position gets snapped.
Now, it's entirely possible the bug is in my network or gameplay system somewhere. However, some people have reported that the snapping gets worse when more than one person moves, making me wonder if the issue is in how I'm rewinding Box2D. Usually, one game is running the actions in real-time like normal, while the other has to rewind to a previous position and do the simulation within a loop. Like I said, I'm saving all bodies' x, y, and linear velocity for each step. I'm not saving anything to do with angles because all the dynamic body instances so far use fixed rotation. Before I deactivate any body I save it's linear velocity to load after it's activated again, because it seems like deactivating causes bodies to lose velocity (I could be grossly mistaken, but I'm looking for anything here). Both client and server use the exact same calls to Box2D, including the ones to step the world (they actually link to the same source file). What else could be causing two otherwise identical simulations to get off sometimes? What other variables might I not be saving and reloading properly? Is there any way momentarily deactivating some bodies' while another is simulated can alter those bodies' simulations? Can simulation between PCs, even with all the same variables, settings, timings, etc, differ in their outcome? It seems like most of the time the snapping is pretty mild, but in a platform game a difference of a few pixels can be the difference between landing on a platform and not, so this is getting frustrating. Thanks for the help!
The game uses Box2D mainly for player collisions and movement. Players can not affect each other physically. Right now there are no interactions between two dynamic objects (there will be eventually, but I have a few ideas on how to handle it). The networking system I've devised to prevent speed and teleport hacking involves making it so both the client and server can rewind specific instances and replay them to the current simulation point with new input. I do this by saving the x, y, linear velocity, and input variables of each player for a set period of time. Then, when I need to rewind, I deactivate all dynamic objects except the one I'm trying to simulate again. The rest don't need to be simulated again because they don't affect each other. The system then gets stepped through it's paces the correct number of times and in theory the object should now be in the correct position. This works great, most of the time. I'm noticed though that under certain circumstances the client and server disagree on the final position and the client's position gets snapped.
Now, it's entirely possible the bug is in my network or gameplay system somewhere. However, some people have reported that the snapping gets worse when more than one person moves, making me wonder if the issue is in how I'm rewinding Box2D. Usually, one game is running the actions in real-time like normal, while the other has to rewind to a previous position and do the simulation within a loop. Like I said, I'm saving all bodies' x, y, and linear velocity for each step. I'm not saving anything to do with angles because all the dynamic body instances so far use fixed rotation. Before I deactivate any body I save it's linear velocity to load after it's activated again, because it seems like deactivating causes bodies to lose velocity (I could be grossly mistaken, but I'm looking for anything here). Both client and server use the exact same calls to Box2D, including the ones to step the world (they actually link to the same source file). What else could be causing two otherwise identical simulations to get off sometimes? What other variables might I not be saving and reloading properly? Is there any way momentarily deactivating some bodies' while another is simulated can alter those bodies' simulations? Can simulation between PCs, even with all the same variables, settings, timings, etc, differ in their outcome? It seems like most of the time the snapping is pretty mild, but in a platform game a difference of a few pixels can be the difference between landing on a platform and not, so this is getting frustrating. Thanks for the help!