Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / Synchronize physics across multiple computers

Author
Message
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 21st Sep 2020 17:58
I have been working on a game for 2 or more players.
It uses physics for both collissions and movement of sprites over the screen.

I did a test with 2 computers running the same program, which shoots a ball from the SAME position, to the same direction with the same velocity.
However, slowly but surely the physics behavior deviates,the balls are no longer moving in the same direction.
We assume this has to do with ,slight FPS differences between the 2 computers

Is there a way to synchronize between the 2 computers (we have full UDP connection between the two) so that the physics movements stay the same?
If not, we cannot build the multi-player game we were planning.

Help is much appreciated,
Thanks,
James
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 21st Sep 2020 21:41
Run the physics simulation on one machine and propagate the details to the other machines
Abiz
11
Years of Service
User Offline
Joined: 14th Nov 2012
Location: Amsterdam
Posted: 21st Sep 2020 22:42
Quote: "Run the physics simulation on one machine and propagate the details to the other machines"


Sounds simple and we throught of that too, but with hundreds of sprites that isn't working over UDP.
The game should be playable by people on different sides of the world.

Imagine a 2 player arkenoid game with each player shooting 50 balls, and blocks in the middle. We had hoped that with all conditions being the same, physics would be the same, but it isn't.
Remember with an FPS & Sync rate of 60, I would need to send UDP data within 0.016 (16 ms) accross the world, and still have time to render it.

I had hoped there was a physics calibration trick possible.
James
blink0k
Moderator
11
Years of Service
User Offline
Joined: 22nd Feb 2013
Location: the land of oz
Posted: 22nd Sep 2020 01:55
Quote: "Sounds simple and we throught of that too, but with hundreds of sprites that isn't working over UDP. "


You are going to have to propagate that information whether you use physics or not
haliop787
4
Years of Service
User Offline
Joined: 22nd Mar 2020
Playing: With reality.
Posted: 6th Oct 2020 06:18
I think you need a server side for this to happen.
The server will send all current users the right amount of "force" to use depending on each system.
Or, the server itself will calculate the physics which will automaticly increase all users Fps cause all they see is Sprites yet no physics calculations at all for any device, just the server but then you may have to find a way to round the corners of sending mass amounts of data to all users.

And you can always do what Battlefield (Dice) which is somehow to benchmark physics which is not a real thing more like "bake" them, like Animations rather then real calculations so it will look exactly the same for all users but this is for scenery mostly rather than shooting a ball (server side physics will be the best but the hardest)
Nadav "Haliop" Rosenberg
Lets make the world great forever.
PartTimeCoder
AGK Tool Maker
9
Years of Service
Recently Online
Joined: 9th Mar 2015
Location: London UK
Posted: 7th Oct 2020 19:30
For a simple pong battle game, what I would do is have 1 client to be nominated as the "simulator" which processes the physics and sends the data (position/rotation ect) to the other clients which use SetSpriteXXX but I would implement a sort of "motion prediction" and only send data when a collision happens and send the balls trajectory info and the client can move the ball or react to collisions, if clients lags the end result is always the same (hopefully ) and only sending on the collisions might buy some time for the clients to catch up, I know pong can get a bit ball crazy so it might not work in a ball frenzy.

If you find a reaction fast solution I'd love to see it.

nz0
AGK Developer
16
Years of Service
User Offline
Joined: 13th Jun 2007
Location: Cheshire,UK
Posted: 15th Oct 2020 03:43
AAA games have this issue in multiplayer and I've not seen one that doesn't.
Any reliance on the client to apply physics will result in variation at some point, unless there's a "master" set of properties broadcast to all.
PSY
Developer
7
Years of Service
User Offline
Joined: 3rd Jul 2016
Location: Laniakea Supercluster
Posted: 15th Oct 2020 15:41
Exactly what nz0 said.

All Worms versions do it that way...


PSY LABS Games
Coders don't die, they just gosub without return

Login to post a reply

Server time is: 2024-04-18 23:00:18
Your offset time is: 2024-04-18 23:00:18