Search Unity

Multiple Camera in your Unity Photon Multiplayer Games

Discussion in '2D' started by MaciejKusztal, Oct 25, 2020.

?

How to create a multiplayer camera system for a 2d mobile game so that players can see each other on

  1. A working system that meets all the requirements in the description, using a single camera.

    6 vote(s)
    75.0%
  2. A working system that meets all the requirements in the description, using a single camera.

    6 vote(s)
    75.0%
Multiple votes are allowed.
  1. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    Hello, I would like to gather information on how I can create a scene or camera system for a multiplayer game. This game is very similar to games like Tetris, Hearthstrone or Pong. Namely, the game is mobile, so the camera must be set so that the players are on both sides of the screen. Given the fact that there will be two players A and B, we will be player A and the opponent will be player B. It is important to synchronize the camera so that they can see each other's moves.
    My question is how to create such a scene (game) system?
     
  2. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    you dont need to synchronize the camera, your problem will be to synchronize everything else, score, piece positions, movement etc.

    After you synchronize everything you just display the information of the opponent on the opponent side. ( Easy, because the client knows you are the main player and the other player is your opponent )
     
  3. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    I was synchronizing all the points. However, I have two player boards on one screen, how can I distinguish between the main player and the opponent?
     
  4. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    well photon view has an owner parameter, if you are the owner then you are the main player, if you are not the owner then it is the opponent
     
  5. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    Thanks, I will use it ;)
     
  6. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    @raarc ,
    Your help was very useful. However, the problem is that I have absolutely no ideas how to create a game system similar to the one from Hearthstone! How should such a scene be created? (I checked YouTube and the forum)
     
  7. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    I must tell you that few people can, if you wanted to pick the hardest kind of game to make it would be multiplayer for sure, network code is a nightmare, you either rely on third party libraries like photon ( which have small communities and thus lesser wealth of information/you are dependent on their services ), or you code your own networking( which is even harder).

    That said, if you wanted to code a game like hearthstone at least it is a turn game( which means you dont have to synchronize the players perfectly) as you would have in a real time multiplayer( like rts or fps or mobas) and is much easier and in fact I think you can do it if you try hard enough.

    But you will have to try quite hard, there is a reason most indie games are single player, you can easily make a good single player game with little coding experience if you are creative, but unless you are really experienced at coding even maintaining a connection between 2 clients will be a challenge.(3rd party assets like photon will make it seem easy to connect players and you will find many tutorials on how to begin, but as you continue to develop your game the tutorials will become scarce since what you need for your game will become very particular and you will hit a roadblock quite early on)
     
  8. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    I am explaining to you. I made a game for two, everything works. However, I want a multiplayer system so that players can play with each other over the network, the game resembles a system like Hearthstone or Pong. The point is that players have half the screen so they can be considered and they play for scoring points. I had no problem creating the scene because I had set up all the objects and the game started. In the current situation, I have to create a code to validate the main player and the second player as an opponent (this part of the screen cannot be influenced by the main player like Hearthstone). I could say it's the only thing I'm not sure how to do.
    An additional cry is the synchronization of adding points, will it be any different (?). I have already done the rest.
     
  9. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    when you say that you made the game for 2 players and now you just want to add the multiplayer is like saying that you made the wheels and now you just want to add the rest of the car.

    The multiplayer is the most complex part ( you are supposed to code the multiplayer first and only then make the game )
     
  10. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    Okay, so let's assume that the game is a one-man game (and I made a complete design change). And now I created a connection to the Photon server, went logged in to the scene. I've already written the code using the Prefabs that form at the beginning of the scene (as they are connected to the server of course). However, I don't know yet why the code that is a component of this object won't work, but I'll skip this topic. The important fact is how to make the main player only observe the movements of the opponent. The answer is the appropriate use of cameras or maybe you need to somehow divide the screen?
     
  11. raarc

    raarc

    Joined:
    Jun 15, 2020
    Posts:
    535
    its better if you post a picture or diagram of what you want because the examples you give are different.( hearthstone is very different than tetris and very different than pong)

    but each player should have their own camera and you have to give them ownership of the camera

    you also have to give ownership of the controls

    then you need to place photon views on game objects you want to network

    then you need to send calls between clients so they can interact

    to do each of these things you will need to watch one different tutorial

    probably you will have to rewrite most of your code, I think you are not understanding very well that you cannot port a singleplayer game to multiplayer without making new code for everything. ( When you start your game you should already know that its going to be a multiplayer and every line of code is made with that in mind. The way you code movement is different, the way you manage your input controls is different, the way you manage your data is different, when you hit play mode you are always testing online(testing an online game offline is useless), etc)
     
  12. MaciejKusztal

    MaciejKusztal

    Joined:
    Feb 4, 2020
    Posts:
    87
    Here I am sending a picture of the diagram (I apologize in advance, but before that nobody asked me for it and I did it for the first time) .
    https://ibb.co/R3QCzbM

    Yes, I am aware that I have to recreate the entire script and game control as a multiplayer game. I'm just going to use the idea and objects that are involved in the game scene.

    Regarding the subject of cameras, someone already told me it, I watched a few guides and read documentation but it did not give me much, because most of them use multiplayer cameras in 3d games, which in fact is not difficult.

    The scene itself is a game in its own right, and so I know I will have to bring the players together and keep them in sync.