Lyian Posted January 8, 2016 Share Posted January 8, 2016 Hi my dear Community, I want to create a multiplayer games which needs serveral checks serverside, so i decided to move p2.js to the node server. This works like a charm, but in general I have a question.Is the phaser implementation of p2.js in any kind different of the raw p2.js file? Especially does the physics of the phaser version behave differently compared to the raw p2.js engine? If yes, why? Any would it then be better in the end to use the phaser engine without physics and then use the raw p2.js file and code my own physics client side with p2? Thanks in advance! Link to comment Share on other sites More sharing options...
chg Posted January 8, 2016 Share Posted January 8, 2016 I don't know that I can speak for the community. But it sounds like your asking if you are guaranteed to get 100% numerically the same results between client and server, and if that's the case while you might see slight better agreement making sure the physics code is an exact match version for version; you likely won't see the same result even if the code is identical! Floating point implementation differ between browsers (eg. optimisations, implementations of operations of functions like trig) and by processor. The you can expect similar answers even to many decimal places, but there will be differences and these difference will slowly add up making the client and server drift apart in their simulations. Now I'm sure you can find some devs that have does similar and either not noticed issues or have hand waved them away and moved on, but I think the correct answer is not to pretend that this is a solvable or even an ignorable issue. So fair warning: my advise is you need to design for the client and server to disagree, not as a bug or a case that suggests tampering but as a matter of course, something that will happen and you ignore at significant risk of pending frustration. Link to comment Share on other sites More sharing options...
Lyian Posted January 8, 2016 Author Share Posted January 8, 2016 Of course I'll add something like checks for the coordinates and so on, which will be flattened if they' won't differ to much. I was asking if I can expect the same physical results between the raw p2.js engine and with phaser using p2 physics! So let us say i drop a ball, with velocity [x,y], what happens if it hits the ground or a wall? Keep in mind that things like friction, damping and so on, are exactly the same.Will be the results the same if I accept some minor differences, which can be removed by server later on? Link to comment Share on other sites More sharing options...
Lyian Posted January 8, 2016 Author Share Posted January 8, 2016 I just checked phasers source code of the p2 engine with the raw p2engine and they're exact the same. So, overall it can be said, that you can expect the same results. The only difference is, that p2.js uses meters as units and phaser pixels, but this can be converted... If I have enough time, I'll will make an example which showcases that the calculations are the same. Link to comment Share on other sites More sharing options...
Recommended Posts