Multiplayer

Sidescroller/Platform

Page 1 of 1

11 Replies - 1982 Views - Last Post: 21 June 2010 - 05:32 AM Rate Topic: -----

#1 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 115
  • View blog
  • Posts: 696
  • Joined: 16-February 09

Multiplayer

Posted 18 May 2010 - 10:13 PM

Does anyone know any techniques or a tutorial about multiplayer networking for a 2D sidescroller/platform game?

I've read a bunch of tutorials about networking but most of the techniques aren't what I would apply to a side-scroller.

The best system that I have come up with is sending keystrokes that state that the remote is either starting to move are stopping. So keystrokes and constant updates is the best system I came up with.

Any better suggestions? The problem with this current system is that latency causes small coordinate differences that must be corrected. The longer the delay in updates, the bigger the inconsistency in coordinates. Nevertheless, during the constant updates, if the difference is huge, there is a noticeable jump between coordinates. I do not think interpolating between the corrected position and the current position is possible for a platform game.

Is This A Good Question/Topic? 0
  • +

Replies To: Multiplayer

#2 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 115
  • View blog
  • Posts: 696
  • Joined: 16-February 09

Re: Multiplayer

Posted 14 June 2010 - 06:16 AM

Any ideas?
Was This Post Helpful? 0
  • +
  • -

#3 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Multiplayer

Posted 19 June 2010 - 06:29 AM

It is possible, though I don't have a good solution for you at the moment. What is usually done is not sending the data every frame of the game, rather about 4 or 5 times a second. Also trying to reduce the amount of data sent is always good. You need to use a combination of smoothing and prediction. Take the last know position and velocity of an object and update it on the client and server. When the next packet comes in, try and smooth things so that they match up. Like I said though, I don't have an algorithm at the moment. This is something that I've only really just started to explore myself.

Lag is your biggest enemy when making networked games, as you more than likely know.
Was This Post Helpful? 0
  • +
  • -

#4 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 115
  • View blog
  • Posts: 696
  • Joined: 16-February 09

Re: Multiplayer

Posted 19 June 2010 - 11:33 AM

Thanks for the reply, [user="SixOfEleven"]. Currently, that's what I am doing. When the player holds down a movement button, a message is sent saying the player is moving in a particular direction. When the player releases a movement button, a message is sent saying the player stopped moving. This way, messages are only sent when a movement starts and stops. For instance, in 1 minute, it is possible for only 1 message to be sent: "start moving".

The problem, however, is that latency introduces a delay on when a message is received so minor position differences will occur. Thus, an update is sent often. The difference in coordinates introduces jitter.

To solve, this it is recommended to "interpolate between coordinates". For instance, instead of simply correcting the position, it should be interpolated to the correct position. However, this seems good for things like top-down, but whatabout a platform game?
Was This Post Helpful? 0
  • +
  • -

#5 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Multiplayer

Posted 19 June 2010 - 11:44 AM

I did something similar in my top-down shooter that used a tile engine for the scrolling background. Would be the same idea as a platfrom game. Let me look at the book I have here. It has a nice smoothing algorithm for dealing with the jerky movements and the player's position.
Was This Post Helpful? 0
  • +
  • -

#6 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 115
  • View blog
  • Posts: 696
  • Joined: 16-February 09

Re: Multiplayer

Posted 19 June 2010 - 11:46 AM

So would the position correction be linear from old position to correct position?
Was This Post Helpful? 0
  • +
  • -

#7 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Multiplayer

Posted 19 June 2010 - 11:51 AM

From what I remember, you try and do it gradually over a couple frames using small changes. You will never be perfectly in synch, just try and minimize the differences. The "client" should be responsible for determining anything that would harm the player.

The game I made I was doing a straight network and wasn't worrying about lag. It is something that I do need to add in at some point when I worry about Internet traffic.
Was This Post Helpful? 0
  • +
  • -

#8 Tom9729  Icon User is offline

  • Segmentation fault
  • member icon

Reputation: 181
  • View blog
  • Posts: 2,642
  • Joined: 30-December 07

Re: Multiplayer

Posted 20 June 2010 - 12:05 AM

View Postsparkart, on 19 June 2010 - 01:33 PM, said:

Thanks for the reply, [user="SixOfEleven"]. Currently, that's what I am doing. When the player holds down a movement button, a message is sent saying the player is moving in a particular direction. When the player releases a movement button, a message is sent saying the player stopped moving. This way, messages are only sent when a movement starts and stops. For instance, in 1 minute, it is possible for only 1 message to be sent: "start moving".

What happens if one of the messages gets lost? Why not consistently send messages if the player is doing something (and stop when they aren't)?
Was This Post Helpful? 0
  • +
  • -

#9 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 227
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Multiplayer

Posted 20 June 2010 - 02:29 AM

View PostSixOfEleven, on 19 June 2010 - 06:51 PM, said:

The "client" should be responsible for determining anything that would harm the player.


Although I can see the logic of that in a platformer ("What do you mean I missed the platform and fell? I saw myself land on it!"), if conflicts with the First Maxim of Networked Applications: Never trust the client. How do you reconcile those two needs?
Was This Post Helpful? 0
  • +
  • -

#10 SixOfEleven  Icon User is offline

  • Planeswalker
  • member icon

Reputation: 1055
  • View blog
  • Posts: 6,643
  • Joined: 18-October 08

Re: Multiplayer

Posted 20 June 2010 - 08:19 AM

If you look closely, client was in quotes. I was not talking client-server architecure here. I'm talking more of a hybrid between client-server and peer-to-peer.

Bandwitdh is limited. Travel time between computers can be quite long perhaps 500ms to 1000ms over the Internet depending on distance travelled and other factors. Latency and missed packets are also a fact of life. There has to be a balancing act of some sort. The player on a remote computer will be more than a little ticked if another computer predicts their death and kills them when clearly, on their computer, nothing happened to cause their death.

OP:
I like the approach taken by the author of the book: Microsoft XNA Game Studio 3.0 Unleashed by Sams when it comes to prediction and smoothing. See if you can find a copy at a library. Chapters 25-29 deal with networking games. It is all about XNA but you should be able to take something away from it.
Was This Post Helpful? 0
  • +
  • -

#11 sparkart  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 115
  • View blog
  • Posts: 696
  • Joined: 16-February 09

Re: Multiplayer

Posted 20 June 2010 - 02:49 PM

View PostTom9729, on 19 June 2010 - 11:05 PM, said:

View Postsparkart, on 19 June 2010 - 01:33 PM, said:

Thanks for the reply, [user="SixOfEleven"]. Currently, that's what I am doing. When the player holds down a movement button, a message is sent saying the player is moving in a particular direction. When the player releases a movement button, a message is sent saying the player stopped moving. This way, messages are only sent when a movement starts and stops. For instance, in 1 minute, it is possible for only 1 message to be sent: "start moving".

What happens if one of the messages gets lost? Why not consistently send messages if the player is doing something (and stop when they aren't)?


If one of those messages gets lost, that would be a bummer... which is why you would make sure that it doesn't get lost. Consistently sending messages if a player is doing something is great, but I am looking more into platform games. Also, if I can send less messages I would like to send less.

For a top-down game, you could send snapshots of the remote client's coordinates and interpolate between the two coordinates. But how do I do this for a platform game? I'm sure it is possible, but I do not know. If I interpolate between point a and point b, the movement would look a bit bizarre, wouldn't you think?

My quickest solution is to send keystrokes: "jump", "move left", "stop moving". Then the remote client would just simulate the movement just the same as receiving data from the keyboard.
Was This Post Helpful? 0
  • +
  • -

#12 dsherohman  Icon User is offline

  • Perl Parson
  • member icon

Reputation: 227
  • View blog
  • Posts: 654
  • Joined: 29-March 09

Re: Multiplayer

Posted 21 June 2010 - 05:32 AM

View PostSixOfEleven, on 20 June 2010 - 03:19 PM, said:

If you look closely, client was in quotes. I was not talking client-server architecure here. I'm talking more of a hybrid between client-server and peer-to-peer.

Fair enough, but I don't think that invalidates my point. Faced with the reality of latency, how do you prevent players from being killed because a remote machine says they died even when they can clearly see on their own screen that they didn't (100% remote determination) without allowing hacked clients to turn the game into the software equivalent of two five-year-olds running around saying "I shot you!" "Nuh-uh! No you didn't!" (100% local determination)?

Years (decades?) of wall hacks, invulnerability hacks, and other assorted client-based cheating seem to present a strong argument against making software running on the player's own system "responsible for determining anything that would harm the player".
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1