Search Unity

  1. Unity 6 Preview is now available. To find out what's new, have a look at our Unity 6 Preview blog post.
    Dismiss Notice
  2. Unity is excited to announce that we will be collaborating with TheXPlace for a summer game jam from June 13 - June 19. Learn more.
    Dismiss Notice

2D Network Movement

Discussion in 'Multiplayer' started by Kalagaraz, Jul 23, 2013.

  1. Kalagaraz

    Kalagaraz

    Joined:
    Aug 26, 2009
    Posts:
    46
    Anyone know the best way to implement smooth 2D networked movement where the server is authoritative?

    I've though of multiple solutions but each have a problem that I can't really figure out.

    1. Client sends "Pressed W key" and "Released W key"

    - Ideal solution, but not sure how to handle latency and client updates. So the player send pressed W key, and on client we immediately start moving the character forward. Server receives command 70ms later, but now it's already behind in the simulation (or rather client is ahead in simulation). if the Release W key is also delayed by exactly 70ms everything is good, we still have 1s of travel. The problem is when they are different and most likely will be. We get different lengths of travel time on the server.

    I've read articles on client side prediction and correction, but the problem is with unity physics we don't have the ability to rewind the simulation back, make corrections in the past, and then run simulation forward with new values again?

    2. Client sends regular position updates.

    - Don't really like this one. can then just get the speed from the derivative and test of speed hacks and such, but the problem is then is how to do collision? Unity doesn't check for collisions when directly setting the positions? Also writing checks for going through walls might be difficult.

    Anyone got any ideas?
     
  2. snacktime

    snacktime

    Joined:
    Apr 15, 2013
    Posts:
    3,356
    Run your server side physics on a sampling of users, and let it run behind, don't make the client wait. I've used this approach on large commercial games for physics, combat engines, all sorts of things. As a general approach it works well because you just can't make the client wait and still have good gameplay.