Search Unity

  1. Welcome to the Unity Forums! Please take the time to read our Code of Conduct to familiarize yourself with the forum rules and how to post constructively.
  2. Dismiss Notice

how to make a splitscreen game?

Discussion in 'Scripting' started by Sickan, Oct 11, 2014.

  1. Sickan

    Sickan

    Joined:
    Oct 2, 2014
    Posts:
    4
    hi i´m trying to make a splitscreen game and i can´t seem to figure out the easiest way to make two controlers since i have used the asset for the firstperson controller and i want to be able to to control the first and secound player with game controlers(ps3/xbox)?
     
  2. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    It's good that you posted this in the Scripting forum, since it's going to take a little scripting.

    1. Make a copy of the first person controller script(s).

    2. Add public properties that you can assign for the controls -- movement axes, jump, whatever you need. For example:
    Code (csharp):
    1. public string horizontalAxis;
    2. public string jumpButton;
    3. //etc.
    3. Change the code that checks Input.GetAxis() and Input.GetKeyDown/GetButtonDown() so they use these properties instead of hard-coded values. For example, instead of Input.GetButtonDown("Fire1"), use Input.GetButtonDown(jumpButton).

    4. For each player, assign the appropriate controls.

    Or, consider creating a "virtual controller" class with properties such as HorizontalAxis, IsJumpButtonDown, etc. Your first person controller can check these properties, completely independent of the underlying input method (e.g., Input.GetKeyDown(), Input.GetButtonDown(), or even AI-supplied inputs).
     
    SniperEvan likes this.
  3. ZO5KmUG6R

    ZO5KmUG6R

    Joined:
    Jul 15, 2010
    Posts:
    489
    You can make a Horizontal2 and Vertical2 axis and check them in the script.
     
    SniperEvan likes this.
  4. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    I see Magic Splitscreen is today's 24-Hour Deal on the Asset Store. I'm not sure if it includes dual controls, but it looks like a nice solution for the screen part.
     
  5. GibTreaty

    GibTreaty

    Joined:
    Aug 25, 2010
    Posts:
    792
    I started working on a splitscreen asset a few days ago inspired by the lego games and then I saw that pop up as the daily deal. It freaked me out, then I saw that it was updated August 15th so I'd be a bit late putting my own asset up there unless I make mine better in some way.

    The problem with splitscreen games in Unity is now you're going to need multiple audio listeners, which Unity doesn't do. There may or may not be an asset for that on the store, but I do know an asset like that exists somewhere because I've seen it.
     
  6. TonyLi

    TonyLi

    Joined:
    Apr 10, 2012
    Posts:
    12,523
    Good point. Looks like most people detach the audio listener from the camera and place it halfway between the players. I suppose it really depends on your game design.

    [EDIT:] On this topic, I just saw that LunaArgenteus has an Input Wrapper that should make it easier to handle multiple controls, as well as an upcoming Split Screen Audio extension.
     
    Last edited: Oct 15, 2014