Search Unity

Sending Player Health

Discussion in 'Multiplayer' started by victoryismine06, May 20, 2009.

  1. victoryismine06

    victoryismine06

    Joined:
    Apr 3, 2009
    Posts:
    21
    Hopefully an easy question. But what would be the best approach to send a player's current health across the network? I basically want everyone to know all network player's current health, deaths, and kills. Just looking for a good approach before I head off to coding. Thanks!
     
  2. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The best approach likely is sending RPCs from the server to all clients when the state of a player changes
     
  3. victoryismine06

    victoryismine06

    Joined:
    Apr 3, 2009
    Posts:
    21
    Ok sounds good. So I have one player be the host, but he isn't neccesarily a client. Is this going to cause some problems? I guess main problem is between the keyboard and my chair at the moment. Any chance you could explain a little further what you mean? Thanks for your advice!
     
  4. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    The idea is simple:

    Only a single point decides about point, health etc changes at all.
    That point is your server
    So the server is the only one with the legitimate right to inform others of the change of those player statistic.

    If that point is a player who is hosting the game or a "server only instance" is of little importance actually :)
     
  5. victoryismine06

    victoryismine06

    Joined:
    Apr 3, 2009
    Posts:
    21
    So on the server have an ArrayList of a Player Class that has sender, health, kills, deaths etc. Client calls a function on the server to update the health, server verifies and tells everyone else.

    I think I'm having the same issue with my change weapon, I need to tell everyone that only I changed my weapon or health, right now if I RPC.Others(), I change the other person's weapon, and he changes my weapon. :/ Thanks!
     
  6. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    No, normally not.
    Commonly, the client is informed of health updates etc from the server.
    The client informs the server of each action he does, the server performs the action and notifies the client again.
    Position updates might potentially be an exception to this, they happen on the client and if required, the server will enforce a correction if the changes are impossible.

    RPC.Others is a problem with above architecture as it bypasses the server.
    In either case: if the wrong object is updated, you potentially don't have an array on the client that maps a Network Player object to the ingame player avatars.


    In both cases, the Network Example might be a good source for some of the concepts.
     
  7. Veli

    Veli

    Joined:
    Mar 10, 2009
    Posts:
    301
    Thats true, but I would really love to see a complete FPS game with source. I am strugling with these things as well and I managed to pull it off... but I am pretty sure that there would be a wiser ways of doing this:p
     
  8. Dreamora

    Dreamora

    Joined:
    Apr 5, 2008
    Posts:
    26,601
    multiplayer FPS with good extrapolation and interpolation of position is a tricky thing as different things depends on the actual game speed and "precision" the game wants to achieve.
    Also Unity is only partially suited as it does not offer a dedicated server which means that player have to host games, which is not a needfully good idea for FPS where low latency is a requirement.

    To create FPS networking you will have to read different non-unity articles on the web for the required theory, but once you have read them, using unity's networking will be a piece of cake in trade (its a matter of using a transform linked to network view for the transform + RPC for shooting interaction + RPC for server driven information updates on client + RPC for player transform corrections if required)

    A fair part of that is covered in the Network Example as it includes animation syncronization, the transform bound to network view and if you check the tps based multiplayer you get an idea how to use the RPC to achieve the rest.


    The old FPS example also might give you hints on how to do things. Never used it, so I can't say much about it.
     
  9. victoryismine06

    victoryismine06

    Joined:
    Apr 3, 2009
    Posts:
    21
    Hmm, yea I wish Unity or someone would put together a little walk through. I looked through the examples and I was able to get a loose grasp on the subject. I'm able to have the players move around and shoot each other. But from then on, the path seems very unclear. Anyone know if they/someone is planning on an actual networking tutorial?
     
  10. ValenJ

    ValenJ

    Joined:
    May 21, 2009
    Posts:
    4
    Hopefully so! Looks like they should pay Dreamora to write one ;)