Search Unity

  1. New Unity Live Help updates. Check them out here!

    Dismiss Notice

Local multiplayer given current project setup

Discussion in 'FPS.Sample Game' started by charles_xl, Dec 11, 2018.

  1. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    44
    Hey everyone!

    Really getting my feet wet with the FPSSample project and working through understanding how the networking layer works. I was thinking for another game mode, what if you wanted to do local split screen or any type of local multiplayer? I'm assuming you wouldn't need to run a server, would the way players are spawned be a little different in that scenario?

    I'm using some of the code in my own project but want the player to be able to switch between online and local multiplayer modes. Anyone have an idea how to set this up? Not sure if this is slated on the roadmap or not.
     
  2. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    Howdy Charles,

    The current project is heavily based on a client/server setup for the current logic. Clients connect to the server, the server sends updates to the clients that the clients see as the networked items (doors, bullets, players, boxes that move) and static items that do not update (building structures) are not networked.

    The scripts in use, run a basic check on all prefabs as I see it "Am I client? If so, disable everything on me" or "else, leave it enabled" for anything networked (doors/characters ect.) Then the server item, acts, and the network pushes the results of those acts down to update the clients view of the acts. This is what the FPS Sample logic is expecting.

    But, if you wanted to use the project to build a local player game, you totally could. You would just need to be sure to cut out all the server requirements when scripting stuff. Or, maybe you could still use the server to connect all of your 'clients' that buy your game. And just use the server side, to pass 'best score globally' and user/password, or social stuff. :) No movement or play data.

    Then you can still use all the assets, see how the new toys are used, ect.

    If you wanted to run two games on the same host, you will have some challenges with Get-Focus and Mouse/Keyboard/Controller inputs. I would run one game, and then use multiple inputs for two players ect. There is even a few assets out there to enable that.

    Good Luck, Have fun
    Micah
     
  3. charles_xl

    charles_xl

    Joined:
    Oct 4, 2016
    Posts:
    44
    Hey Micah,

    Thanks for getting back to me. Yeah all of that makes sense, but I think the player game objects would have to be entirely different then right? There is no way to reuse what's already there, ideally I'd have a prefab that can represent the player regardless of being local or online. It also becomes tricky when you have let's say 2 players local playing against 2 players online, in that case the two local players would have to have their updates sent through the server, same in a LAN instance so the only scenario where the server wouldn't be needed would be everyone playing on the same machine.

    What are your thoughts?
     
  4. AggressiveMastery

    AggressiveMastery

    Joined:
    Nov 19, 2018
    Posts:
    206
    Hello Charles,

    I assume you have seen Peter's networking video (embedded or linked below.)

    That said, you ARE able to use the existing pre-fabs and assets, you will just need to dig into them and learn what you need to disable/remove, redo, modify ect.

    You could also package the results on the local client players inputs, and send those off to a server to sync networked players/server, but then you are just returning to the same client-server setup FPS Sample is made for. Which, is a good thing :)

    Check out this vid:
     
unityunity