Search Unity

Networking for racing game

Discussion in 'Multiplayer' started by maxcreigs, Feb 26, 2010.

  1. maxcreigs

    maxcreigs

    Joined:
    Feb 20, 2010
    Posts:
    4
    I'm currently in the process of reviving a racing game project of mine. I started thinking of how to approach networking, in which I don't really have much experience. From what I understand, I should really use UDP for most things, since it's a fast-paced game. However, I'm between 2 approaches:

    1)The server handles the simulation, and send packets to the clients that contain the position/orientation of every moving body.
    2)Each client sends to the server input messages(like 'front key was pressed'), and the server broadcasts those messages to all other clients, which handle the simulation locally, based on those messages.

    I would like to ask, from those 2 approaches, what would be the most sane and efficient? What are the pros and cons of each one? Also, are there any other methods I'm not aware about?

    Any links to resources talking about this would be also welcome. Thanks!
     
  2. Yorick2

    Yorick2

    Joined:
    Jan 24, 2009
    Posts:
    297
    The first approach is going to be way too slow...

    The second approach is better but will become more and more inaccurate over time.

    What you want to do is to have each player do the physics for their own car and broadcast both their userinputs and calculated positions.

    Then on all machines you use the inputs to drive the car (physics, particles, engine sounds etc) but you interpolate/override the physics with the positions from the network.