Author Topic: Authoritative\Semi-Authoritative logics & 2D platformer  (Read 4902 times)

Norteck

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Authoritative\Semi-Authoritative logics & 2D platformer
« on: February 27, 2015, 05:00:26 AM »
Hello community.

Currently I've a problem with implementing authoritative (or at least semi-authoritative) logics for 2D platformer.
The biggest problems is in movements of course. Actually there are only horizontal axis for moving left\right and vertical for jumping.

So, the problem is in making authoritative approach of this movements with smooth client prediction. For now I'm trying this logics:

For movements I used Character Controller as it's pretty deterministic (isn't it?).

Client:
- simulate movement (prediction itself)
- buffer input, current position and serverTime and send it to the server 4 times per second or on any change of horizAxis \ if jumped

Server:
- simulate gravity and last received input state
- if any new input received - update last input state, then calculate distance between current server position and received client position (with input), on error more than 1 for example - send correctState RFC where client will be moved to the right position (I've tried to compare received position with buffered server position, where received client's timestamp <= buffered.timestamp, it gives some improvement, but not that much)

Unfortunately this approach doesn't work smoothly on the client which is trying to predict movements, too much jittering of the character because of state corrections from server (SpringTransform attached on separated graphics gameobject). Most amount of jitter\lag appears while jumping, pure horizontal movements quite synced.

I would be grateful for any suggestions and hints.

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #1 on: March 01, 2015, 05:15:01 PM »
First thing's first... what's "Server" in your case? Server in TNet's terms is just a stand-alone executable that you actually connect to (or TNServerInstance). It has no game logic. It doesn't inspect packets. It merely forwards packets to their intended client destinations.

Did you mean "Host"? A "host" is the authoritative player. There can be only one "host" per channel.

Now onto your issue... don't do it the way you're doing it. Let each client do their own movement logic. Simply send the action that causes the movement -- for example a pressed key state. Each client can do their own logic that would result from this action -- jumping for example. Then every few seconds have the object's owner send updates along the lines of "I'm currently at position XYZ", and the other clients will then adjust their position to match, just in case simulations deviate too much.

Norteck

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #2 on: March 01, 2015, 07:51:09 PM »
Thank you for your response, Aren.

Sorry for not being precise, by "server" I meant "host" as authoritative player. I understand the concept of TNet server.

If I understood correctly, with such a model as you adviced we will get peer-to-peer synchronization of objects and the host will not be authoritative over clients (at least in the movements of players).

Currently everything works smoothly on all game entities (host and other clients) except player of non-host client. So for him I'm trying to implement "Dead reckoning" algorithm, the most simple version of it, if there is any :).

I appreciate your advice.
« Last Edit: March 01, 2015, 08:06:15 PM by Norteck »

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #3 on: March 03, 2015, 05:56:38 PM »
Ideally you want each player to be in 100% control of their own avatar, rather than the host. This will make each player feel responsive, even if there is lag. It's generally a bad idea to have players be controlled by someone else. You press a button, then something happens half a second later... it's not a fun experience.

Norteck

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #4 on: March 04, 2015, 02:01:51 PM »
Ok, I understand, you're against authoritative logic for movements. Then how to best treat shooting physically based projectiles (not very fast, without raycasting I think), like a thrown apple. Should I instantiate them on the host and do all checks on it, while on the clients just render visuals, but the true result will be established by host?

And another question about moving objects like lifts or platforms with which the player can interact: I guess they also have to be controlled by host, through sending updates of their position\rotation to the clients. The only problem, if clients tell each other where they are, and there is a delay while updating position\rotation of platform between the host and clients, when one player will be standing on the platform, others will see him sliding a bit on this platform (more lag, more this effect appears as I understand). So the question: what is the right way of implementing this? Maybe making the player's gameobject as a child of the moving platform on all clients?

ArenMook

  • Administrator
  • Hero Member
  • *****
  • Thank You
  • -Given: 337
  • -Receive: 1171
  • Posts: 22,128
  • Toronto, Canada
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #5 on: March 05, 2015, 10:36:28 PM »
I actually played around with a bunch of settings in Windward -- host deals damage, aggressor deals damage, and victim deals damage. In the end, I made it a flexible option that I can change with a setting, but it's defaulted to aggressor dealing damage. This way players with high ping won't be able to cheat their way out of a fight. If the player shoots and hits an enemy, damage gets applied by whoever made that shot. Even if that person lags, and isn't there anymore.

At first I had it set to "victim deals damage", and it resulted in certain player intentionally lagging his outbound traffic to a 1 second delay so he'd be invincible while being able to shoot others with abandon. "Aggressor deals damage" was much more fair.

Since players would periodically update their position, even if lag causes some players to see another as never making it onto the platform, the next sync update would correct that. You can even send a message when a player enters a new movable region, like a platform or a region with altered gravity informing others that this occurred, and that all movement should now be relative to that region.

Norteck

  • Newbie
  • *
  • Thank You
  • -Given: 2
  • -Receive: 0
  • Posts: 4
    • View Profile
Re: Authoritative\Semi-Authoritative logics & 2D platformer
« Reply #6 on: March 06, 2015, 07:26:06 AM »
Thank you for all your advice. I will try to do it this way and experiment.