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

How do FPS games render the character in multiplayer?

Discussion in 'Editor & General Support' started by Duskling, May 6, 2012.

  1. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Howdy.

    I was wondering, how do fps games render the character during multiplayer.

    I mean, other players see you as a full, animated character, with whatever weapon you have equipped.

    But the player himself only sees a pair of arms with a gun, which I think is a seperate mesh.

    Are they rendered on seperate layers?
     
  2. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    In what kind of multiplayer? splitscreen or online?
     
  3. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Online.
     
  4. tatelax

    tatelax

    Joined:
    Feb 4, 2010
    Posts:
    1,168
    The engine only renders what you see.
     
  5. Jaimi

    Jaimi

    Joined:
    Jan 10, 2009
    Posts:
    6,204
    Each person's machine is creating the world and rendering it specifically for that person. It's rendering what it thinks that world looks like. It's never going to be exactly the same as what other people are seeing because of the latency. So, since you are creating a world just for you every frame, you create it as you want it to be. When you create yourself, you only show arms and a gun. When you get input on where the other players are (you have to guess a lot), you draw them with full bodies. This leads to cheating also - People can hack games and make walls transparent just for them, or remove lighting so they can see people hiding, etc.
     
  6. TehWut

    TehWut

    Joined:
    Jun 18, 2011
    Posts:
    1,577
    In your game, you only see your model with the high poly hands and guns, and then everyone else is viewed as full characters with lower poly guns etc, which allows for more detail or whatever. As to how this is done, by layer perhaps, is game specific.
     
  7. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    I'm very confused as to how I would do this :L
     
  8. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    You dont, that is why the people at infinity ward get paid lots to do that.
     
  9. lmbarns

    lmbarns

    Joined:
    Jul 14, 2011
    Posts:
    1,628
    I imagine when JimmyAwesome629 joins the game and each client is updated with his name, position, etc it tells each client to instantiate Jimmy's prefab, if there's player customization it passes what options jimmy selected before joining the game.
     
  10. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Hm... That makes sense.

    So pretty much through RPC calls, Jimmy's client is sending out info such as his rotation, position, and weapon, current animation, etc. Then jimmys model is instantiated on the other clients and updated with that information every update.

    Now on jimmys client, he only sees his current gun in his hands and that's it.

    Gosh this is confusing. I will see if I can figure this out more in depth later on.
     
  11. TylerPerry

    TylerPerry

    Joined:
    May 29, 2011
    Posts:
    5,577
    You dont need to send the info on wich gun he is using more then once though as it wouldn't change.
     
  12. George Foot

    George Foot

    Joined:
    Feb 22, 2012
    Posts:
    399
    MrDuskling, with Unity's networking you would normally get the joining peer to use Network.Instantiate to create a GameObject on every peer in the session. This is not necessarily a renderable object - it's a placeholder that will get moved around by the networking system as and when messages are received. On top of that, the peer locally creates the hands/gun model, attaches a camera, and arranges for user input to move the character around. The other peers, when they create their shadow of the joining peer's player object, will also create the fully animated visual model, so their local player can see where the remote player is.
     
  13. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    This. Multiplayer is an illusion - you can't have multiple computers rendering the same world. How it actually works is that each computer has its own world that tries to imitate that of the other players'.
     
    spectrethegameboy likes this.
  14. Morning

    Morning

    Joined:
    Feb 4, 2012
    Posts:
    1,141
    How is that an illusion? There's multiple people interacting, that's a multiplayer.
     
  15. yuriythebest

    yuriythebest

    Joined:
    Nov 21, 2009
    Posts:
    1,121
    what DallonF is trying to say is that, especially in more complicated games with physics n stuff, each players "world" can be slightly different (for example, small insignificant objects like decals/pieces of trash/flying newspapers/exact positions/etc can be different), also if it's first-person, usually just the arms for the "active" player are rendered while a full model is created for the "others", etc so in a sense the word "illusion" would be accurate, but then again ALL games are illusions hehe
     
  16. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Pretty simple. Proxy/remote player prefabs are a full character mesh. Local, player-owned player prefabs have no character mesh, just hands and weapons.
     
  17. Gigiwoo

    Gigiwoo

    Joined:
    Mar 16, 2011
    Posts:
    2,981
    There is no ground truth in multiplayer games. Even if you are publishing data at 60 FPS, there is still latency in the transmissions. Each client renders what it 'thinks' to be true. It's called Dead Reckoning - there's a chapter on it in Game Engine Gems 2.

    Gigi.
     
  18. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    Right. A multiplayer game isn't one game with 16 (or however many) players looking at it, its 16 separate games, kept as closely synchronized as possible through network updates.

    What would happen in this case is a new player would connect, and the server (or the player, if it was non-authoritative) would say "hey, a new player connected. Tell the new player to create a player prefab in his game that has animated hands/weapons and no body mesh, that he owns and controls. Tell all other players to create a proxy prefab in their games, that has an animated full body mesh. When the owner player moves his prefab, he'll tell me, and I'll tell all the other players where to move the corresponding proxy, to keep them in sync."
     
  19. DallonF

    DallonF

    Joined:
    Nov 12, 2009
    Posts:
    620
    They're not interacting. Say Player A shoots Player B in a "multiplayer" FPS.
    What actually happens is that Player A, in his game, shoots an NPC that just happens to be mimicking the actions of Player B in his own game.

    Meanwhile, in Player B's game, the NPC that represents Player A receives word of what Player A has done, and proceeds to shoot Player B.

    The only true multiplayer games are those that have multiple players on the same console. Splitscreen works very differently than online, so the OP's challenge is actually more of an issue here.

    Online multiplayer is a very powerful illusion, but it's extremely difficult to create if you don't recognize it for what it is and take advantage of the differences between the connected worlds.
     
  20. Morning

    Morning

    Joined:
    Feb 4, 2012
    Posts:
    1,141
    It's true that each world is simulated on it's own, but state syncing from a master server (or other players in case of p2p) makes it a multiplayer game as all these NPCs are still controlled by players.
    Even in a singleplayer game the player is controlling an npc that receives commands from an input device.
    That's why in unreal they're called pawns, because each player gets to control one or more of them, you're never there, you're just controlling a chess piece on a board.
     
  21. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Hey guys, This is still based on the above topic:

    How should I actually have the weapon in the players hands?

    I took some time to investigate and it seems alot of FPS games have objects with the gun and hands in one model. What I was going to do is position these "hand and gun" models in the editor, deactivate them, and then activate them through code based on if they are selected in the inventory.

    But wouldn't it be more "efficient" to just instantiate the "hand and gun" model at runtime when I select the gun, and then destroy it when I deselect it?

    This also sort of pertains to the third person model aswell. Should I make the weapons childed to the weapon bone in the editor and activate them through code or should I instantiate them on the weapon bone at runtime?
     
  22. TehWut

    TehWut

    Joined:
    Jun 18, 2011
    Posts:
    1,577
    No, the previous suggestion is the way to go, and it is also how it is done in the DB weapons package and other Unity kits. Destroying objects leaves the issue of remembering ammo count e.t.c You could add all of these weapon objects under one camera, into an array, and then iterate through the array to enable / disable these objects. (e.g through scroll wheel)
     
  23. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Okay, Thanks!

    Just wanted to be 100% sure.
     
  24. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Alright, based on what some people have said here and what I have read on the internet, I have decided to do this:

    Code (csharp):
    1.  
    2. Player ( Empty GameObject, Holds movement, mouselook, weaponcontrol, etc )
    3.     FirstPerson( Camera )
    4.         GUN OBJECTS GO HERE
    5.     ThirdPerson( Full mesh of player )
    6.  
    On the Player object, the movement script tells ThirdPerson to ignore the x and z rotation of Player so that it isn't effected by mouselook. If the network view isnt mine, FirstPerson will set active to false and ThirdPerson will set active to true, and vice versa for if the network view IS mine.


    I don't know if it's just me or am I doing something VERY wrong here, I mean am I doing this inefficiently or incorrectly. It just feels very unorganized and not good programming.
     
  25. TehWut

    TehWut

    Joined:
    Jun 18, 2011
    Posts:
    1,577
    Honestly it looks pretty good to me, but I'm no programmer. What you could also do is have two cameras, one for first person that renders the first person object, and then another camera that renders the third person object. Whatever you feel is best though.
     
  26. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    Don't mean to be rude tehwut,

    But is there any programmer that is experienced enough to tell me if I am doing this correctly?
     
  27. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
  28. SirGive

    SirGive

    Joined:
    Sep 27, 2010
    Posts:
    384
    most FPS multiplayer games I've seen had a capsule as the "gun holder".

    I've been glancing at this thread, but what you'll want is a server/client built into one. Then develop a way for an instance of your game to act as a server and allow clients to connect to it. (unless you're doing some big online stuff, but if you're asking this much about it - best to go with small multiplayer).

    The server needs to either : A) control where every other player is (through server request) or B) just keep track of their status and send it to each client.

    - I should really read. Been glancing on the sly.

    Why not just have a lobby that takes care of setting up the host and then start the game - initialize "us" and clients monitor server for position updates of the other players? So its a completely different script for player and other player. Server sets up cubes for the time being until you can get the animations synced.

    Otherwise combining both the *other player* and playable player might get messy.
     
    Last edited: May 8, 2012
  29. PrimeDerektive

    PrimeDerektive

    Joined:
    Dec 13, 2009
    Posts:
    3,090
    That's pretty much how I would do it, except you may as well destroy the one not being used, rather than set it inactive; unless you plan to let people spectate from first person or something.

    Just disable the movement and mouselook scripts on proxy prefabs (!NetworkView.isMine).
     
    Last edited: May 8, 2012
  30. Duskling

    Duskling

    Joined:
    Mar 15, 2011
    Posts:
    1,196
    The game will not be an mmo or anything, the player will be able to host a LAN game or port forward to allow players from all over the place.

    Thanks for the help guys. I will probably experiment with this a lot to figure out what works best for me. Right now I am going to try out managing both the First Person and the Third Person on the client. I will post results.