Search Unity

  1. Megacity Metro Demo now available. Download now.
    Dismiss Notice
  2. Unity support for visionOS is now available. Learn more in our blog post.
    Dismiss Notice

Multiplayer Deathmatch

Discussion in 'Multiplayer' started by Antonio, Dec 3, 2008.

  1. Antonio

    Antonio

    Joined:
    Dec 3, 2008
    Posts:
    14
    Hi evereyone!
    I want to create a multiplayer game were you can hurt other gamers...
    I started from the network example of unity, I can punch but I am not able to hurt other players...

    I added a ThirdPersonCharacterAttack, ThirdPersonStatus, GameHUD, taken from the 3rd Person Tutorial, then I modified them to make them work.

    I changed the ApplyDamage in ThirdPersonStatus adding "@RPC", then I call
    Code (csharp):
    1.  
    2. networkView.RPC ("ApplyDamage", RPCMode.All, punchHitPoints);
    3.  
    in the function DidPunch in the ThirdPersonCharacterAttack instead of the standard ApplyPunch.

    I edited ThirdPersonSimpleAnimation to be able to see the punch animation:
    Code (csharp):
    1.  
    2.     // Fade out walk and run
    3.     else if (attack.IsFighting() == false)
    4.     {
    5.         animation.CrossFade("idle");
    6.         SendMessage("SyncAnimation", "idle");
    7.     }
    8.  
    and I commented the DidPunch function

    I edited ThirdPersonNetworkInit in this way:
    Code (csharp):
    1.  
    2.     // This is just some remote controlled player
    3.     else
    4.     {
    5.         name += "Remote";
    6.         GetComponent(ThirdPersonController).enabled = false;
    7.         GetComponent(ThirdPersonSimpleAnimation).enabled = false;
    8.         GetComponent("NetworkInterpolatedTransform").enabled = true;
    9.        
    10.         GetComponent(ThirdPersonStatus).enabled = false;
    11.         GetComponent(ThirdPersonCharacterAttack).enabled = false;
    12.         GetComponent(GameHUD).enabled = false;
    13.     }
    14.  
    Now I am able to punch but the RPC is not called on every player but only on who punches. And so I can only hurt myself and not others...

    Can someone help me?
    Thanks
     
  2. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Very hard to say..but I guess it could be something like this:

    You call the RPC successfully on all players, the the attack/hurt code can only be called on the local player, and therefore never works on other players. If this is the case, check of the hurt code is enabled on 3th parties.
     
  3. Antonio

    Antonio

    Joined:
    Dec 3, 2008
    Posts:
    14
    I wrote a print into the RPC function and I saw that it was called only once, it printed out the NetworkView.viewID of the attacking player.

    Code (csharp):
    1.  
    2. print (networkView.GetComponent(NetworkView).viewID.ToString());
    3.  
     
  4. MikeHergaarden

    MikeHergaarden

    Joined:
    Mar 9, 2008
    Posts:
    1,027
    Have you run both client and server via the editor at least once, to be able to check for errors more easily?

    Also note that you can open up the editor twice, to run both client server via the editor.
     
  5. Antonio

    Antonio

    Joined:
    Dec 3, 2008
    Posts:
    14
    I ran the client and the server with the editor (not in the same time) and I didn't received errors.
     
  6. rozgo

    rozgo

    Joined:
    Feb 7, 2008
    Posts:
    158
    How did your deathmatch go? You should try using straight sockets, as its very simple and efficient to create a realtime deathmatch synced under 64 bytes per player, 10-15 times per frame. UDP will handle this incredibly fast.