ODE Multiplayer Solution
Blitz3D Forums/Blitz3D Programming/ODE Multiplayer Solution
| ||
Hello friends. I have been working with Ode very hard, and now i have it tuned i have developed a multiplayer racing game with great success. Lot of people are asking how to synchronize all the computers. Well, here is my solution: Syncronize all computers exactly is almost impossible due to lag. So the way is to synchronize positions with the lag time as difference. Use the same time for ODE Step in all computers (of course...). Then you can know the lag (calculate the time between messages). The tricky is to send the actual position, rotation and velocities (angular and lineal) and a vector with the changes to the world (keys pressed normally). Then when the client receives the data, Update the position, rotation, etc of the bodies and use the vector to keep upgrading the bodies until the next packet arrives. The interpolation is made automatically by ode, because the car (for example a car) will move in response to keys pressed. If there is too much lag between connections then you should refresh the car's position later, using the lag time. In this case you will see the other car's move later than the original one, but it will move smooth. I will release a short demo soon. I have tested with two computers connected using ADSL and the results are amazing! Good Luck! |
| ||
Sorry, of Course the position update and the key pressed updates are not the same. You Update the key's and when new packet arrives, update the old packet position and then keep updating they keys until the next one... |
| ||
Thats awesome, cant wait to see the demo. |
| ||
^ second that - can't wait to see the demo :) |
| ||
With the Wrapper version i have now i am having a little problem. Getting Body Rotation and Setting it with the values i got gives me different results. Seems like a normalization problem. Since Two days i am working on it, hope i don't need to give it much more time... :( :( :( |
| ||
Don't forget about these guys: const dReal * dBodyGetForce (dBodyID); const dReal * dBodyGetTorque (dBodyID); Return the current accumulated force and torque vector. The returned pointers point to an array of 3 dReals. The returned values are pointers to internal data structures, so the vectors are only valid until any changes are made to the rigid body system. void dBodySetForce (dBodyID b, dReal x, dReal y, dReal z); void dBodySetTorque (dBodyID b, dReal x, dReal y, dReal z); Set the body force and torque accumulation vectors. This is mostly useful to zero the force and torque for deactivated bodies before they are reactivated, in the case where the force-adding functions were called on them while they were deactivated. |
| ||
Here's some more stuff on this topic: http://69.55.229.29/archives/2004/12/zen_of_networke_1.html http://www.gaffer.org:8080/articles/ [see bottom article] (Both by the same guy.) |
| ||
@wayne: I don't need to send and receive the acumulate forces, cause this is one different accumulation per frame. Then, cause i send the input, the force is automatically calculated and applied correctly. @BlitzSupport: Wow, Great links! Thanks! What the link says is almost what i have been doing! (so i am not so bad...) The problem is that is not working in my system: rx = dbodygetrotationx(b) ry = dbodygetrotationy(b) rz = dbodygetrotationz(b) dbodysetrotation(b,rx,ry,rz) That Rotates the body, instead of doing nothing. |
| ||
Ooooooook, problem solved. I have added quaternion functions, so i use internal quaternions for getting and setting data across the networks, and all ok. Now i am working on optimize the input vector. When tested over ADSL with 120ms is good, but i want it very good (collisions included). I am going to try to reduce the float values to 2bytes (lossing accuracy, no problem i think), so i can send larger input vectors. Any idea what is a good rate to send the information? (now i send 5 times a second) |
| ||
Ok, for those interested i must say that my ODE Multiplayer demo is running perfect in no collision World (any lag, any number of players). The problem is that i cannot predict or buffer collision states. I think this is a non solution problem. So most racing games disable collisions for internet playing. Anyway, any good idea? |
| ||
I liked this article on the subject. http://www.gaffer.org:8080/articles/NetworkedPhysics.html |