Search Unity

Making an object go from player 1s screen to player 2s screen?

Discussion in 'Multiplayer' started by Basiltheruler, Mar 10, 2017.

  1. Basiltheruler

    Basiltheruler

    Joined:
    Mar 10, 2017
    Posts:
    1
    I was thinking about making a 2d game on Android with unity, but I was just wondering if it's possible to make an object (ex. like while playing pong, the 'ball') leave one person's screen and enter the opponent's screen. I understand that I will have to make the two players connect via wifi or Bluetooth but after that I'm not entirely sure how to go about it. I can't find any tutorials online about this either.
     
  2. robochase

    robochase

    Joined:
    Mar 1, 2014
    Posts:
    244
    hey! sounds like a fun problem! unity makes this kind of thing easy, fortunately. you can plop a camera in the scene and move it around where ever. unity will draw the camera's view to the screen for you. so for your game idea, you'd want one players' camera to be positioned on one area in the world, and the other player's camera would be pointed elsewhere. think of it like this - each camera is drawing a rectangle of stuff to the screen. P1's camera draws from 0..100. P2's camera draws from 101..200.

    networking wise, you just deal with world coordinates and each players' camera should draw whatever it sees.

    does that make sense?
     
  3. donnysobonny

    donnysobonny

    Joined:
    Jan 24, 2013
    Posts:
    220
    So ultimately, your first goal would be to set things up so that you're working over bluetooth. Normally I would recommend against multiplayer over bluetooth due to the throughput and other issues that you tend to face, but for a game that is as simple as this, you should find it to be okay.

    I wont go into the technical here (let me know if you want more detail), but ultimately unity doesn't support networking over bluetooth by default. There are a few assets though that work, particularly for android, such as the one mentioned here: https://forum.unity3d.com/threads/android-bluetooth-multiplayer-new-version.188667/. This pretty much lets you use unet as is, where the connection is handled locally over bluetooth.

    As for the actual logic of your game: having two screens where the ball appears to travel from one screen to the other, the easiest and most feasible option would be to just make it so that both player cameras are rotated 180 degrees from each other (so that the bottom side of the camera is the south side of "their" side of the playing field, and the top side of the camera is the north side of "their" side and the center of the playing field). The actual game world (shared between the two players) would consist of both sides, but the player effectively only sees their side through their camera. Then everything else should come naturally.

    Hopefully this helps. Let me know if you have further questions.