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 / Network Smoothing

Author
Message
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 25th May 2013 21:12
I've had a project running for some time that I've happily networked. The game uses box 2d for it's calculations, which is where the problems are. Naturally, if I don't update the physics on the client end, the game won't be smooth, but I've been unable to project proper positions for clients with box2d. If I force both the host and client to step box2d by a consistent interval, it is near perfect, but when using timer based movement the client ends up with irritating jitters. Currently, the client deactivates sprites that receive network data in a frame and lets the others predict their positions. I've also tried sharing the host's frame steps and blending them with the that of the client's, but it still has little effect. Interestingly, if I let the client update all sprites, as opposed to those already positioned properly that frame, it appears smoother than what I assumed was the 'proper' method. Does anyone have any suggestions?

swis
Joined: Tue Dec 16th 2008
Interstellar
baxslash
Valued Member
Bronze Codemaster
17
Years of Service
User Offline
Joined: 26th Dec 2006
Location: Duffield
Posted: 25th May 2013 21:37
You might need to send position and velocity data...? It shouldn't get too far off that way.


this.mess = abs(sin(times#))
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 25th May 2013 21:51
Quote: "You might need to send position and velocity data...? It shouldn't get too far off that way."

I already do. That's why I update the client's physics I could upload an example here, but I think the problem is pretty self explanatory. I think somehow I have to account for the time it takes packets to travel to the client because the client will attempt to keep it real time, as opposed to delayed. I'm not sure how this could be done though :/ Something using the ping?

swis
Joined: Tue Dec 16th 2008
Interstellar
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 25th May 2013 22:28 Edited at: 25th May 2013 22:29
i would send the pos. from server to client with timestamp,
and at the client get all messages and ignore the time in the past until the last pos..
then moving indirect to the new pos., fast and smooth as possible
depending on difference old-new pos.
no physics at client side.
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2013 22:54
I'm confused, why aren't you just letting box2d update it all anyway? How is it networked to a server? What's the server do?

"You're all wrong. You're all idiots." ~Fluffy Rabbit
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 25th May 2013 22:54
Quote: "i would send the pos. from server to client with timestamp,
and at the client get all messages and ignore the time in the past until the last pos..
then moving indirect to the new pos., fast and smooth as possible
depending on difference old-new pos.
no physics at client side. "

hmmm that's an interesting idea but it wouldn't always be accurate if I understand what you're saying correctly. (What if something was repositioned instead of moving on its own?) Plus the issue of projecting the new position correctly would still occur.

swis
Joined: Tue Dec 16th 2008
Interstellar
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 25th May 2013 23:00
Quote: "I'm confused, why aren't you just letting box2d update it all anyway? How is it networked to a server? What's the server do?"

The server performs all of the "official" game calculations with box2d and sends this information to the clients. The problem is that these packets don't always come together evenly. If I updated the client's physics each update, some sprites may have been updated by the host already, and some not. The timing wouldn't be even.

swis
Joined: Tue Dec 16th 2008
Interstellar
Phaelax
DBPro Master
21
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 25th May 2013 23:06
Letting the server do the calculations for all the clients sounds like a very bad way to me. Typically the client would do the calculations and position updates then send the new coordinates to the server to relay the player's position to the others. If the other clients don't receive packets pertaining to another's position, then each client would then theoretically guess where that player would most likely move.

"You're all wrong. You're all idiots." ~Fluffy Rabbit
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 26th May 2013 00:06
Quote: "Letting the server do the calculations for all the clients sounds like a very bad way to me. Typically the client would do the calculations and position updates then send the new coordinates to the server to relay the player's position to the others. If the other clients don't receive packets pertaining to another's position, then each client would then theoretically guess where that player would most likely move."

That would double the amount of delay between to clients though Plus, while I doubt it's a concern for my program, that method creates the perfect opportunity for hacking, as opposed to only accepting direct user input, so it's usually not a great practice. Lastly, if the clients aren't asked to do the heavy calculations it greatly lightens the load on them, which is what I'm looking for as some devices could be mobile.

swis
Joined: Tue Dec 16th 2008
Interstellar
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 26th May 2013 10:27
ok, its not pixcel perfect but almost accurate.
the timesteps are very small, i think you don't see a degree different.

Quote: "What if something was repositioned instead of moving on its own?"


you can send a message with flag "jump" and do this direct at client side.
bitJericho
22
Years of Service
User Offline
Joined: 9th Oct 2002
Location: United States
Posted: 29th May 2013 05:28
You could try blending again but use some fancy interpolation functions. See the "The Useful Community Functions Project" thread for all your interpolation needs. This seems like the best way to go about it. Perhaps somehow link the amount of interpolation based on how far off the timing is. Stretch it more towards the client when the timing is way off, or more towards the server when the timing is close.

Visit my blog http://www.canales.me.
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 31st May 2013 18:17
Quote: "You could try blending again but use some fancy interpolation functions. See the "The Useful Community Functions Project" thread for all your interpolation needs. This seems like the best way to go about it. Perhaps somehow link the amount of interpolation based on how far off the timing is. Stretch it more towards the client when the timing is way off, or more towards the server when the timing is close."

I was really hoping to always use the host update positions, they are the 'true' placement, but I think you're right Jericho, I'll probably have to blend them somehow. I'll take a look

Quote: "you can send a message with flag "jump" and do this direct at client side. "

of course haha I wasn't thinking

Quote: "ok, its not pixcel perfect but almost accurate.
the timesteps are very small, i think you don't see a degree different."

That's true but how about cases like collisions? That's a slightly better example. It seems easier to simply use the same calculation system the server uses.

swis
Joined: Tue Dec 16th 2008
Interstellar
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 31st May 2013 19:02
if you use physics, its better they are run only at server side,
the collisions are there.
the input device at client send only her inputs to server.
just try what is better.
swissolo
14
Years of Service
User Offline
Joined: 9th Jan 2010
Location:
Posted: 31st May 2013 19:07 Edited at: 31st May 2013 19:19
Quote: "the input device at client send only her inputs to server."

This is what I do.

Quote: "if you use physics, its better they are run only at server side,
the collisions are there"

The problem is my client network smoothing is already bad enough using the physics system. I can't imagine how much worse it would become if I tried doing it myself. That's certainly a great alternative if I can get it working this way and need a FPS boost, but I already expect users to be able to play offline/host, which both use the physics calculations anyways.

Edit: On a side note, is anyone else having trouble with the getNetworkClientPing() command? It just keeps returning 0 for me when I try to get the ping from the host to a client.

swis
Joined: Tue Dec 16th 2008
Interstellar

Login to post a reply

Server time is: 2024-11-24 13:46:53
Your offset time is: 2024-11-24 13:46:53