Search Unity

Third Party Photon - 2 Players, One Camera Problem

Discussion in 'Multiplayer' started by PHPGator, Dec 16, 2014.

  1. PHPGator

    PHPGator

    Joined:
    Nov 4, 2014
    Posts:
    7
    We are creating a basic multiplayer game. The issue is difficult to explain.

    Computer #1 / Player #1: Host of the game, spawn players fine, camera is attached appropriately.

    When a second player joins the game, Computer #2 now controls the camera (appears to be only one in the scene, but each player should have their own).

    Computer #1 now sees itself in 3rd person and the camera is controlled by Computer #2.

    Computer #1 can still move their own character, but it is no longer a first person point of view.

    Any suggestions on what the problem could be?
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    There is a section called "Fight for Control" in our tutorial, which handles a case very much like yours:
    http://doc.exitgames.com/en/pun/current/tutorials/tutorial-marco-polo

    You basically have to make sure that the cam in each running client is following the locally instantiated character instead of the last one created. This is can be done with a check of the PhotonView on it. Check isMine == true before you assign the character as cam target and before you apply input to the character, too.
     
  3. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    This part of the tutorial is poorly explained. It seems a lot of people had issues with it here. The tutorial is missing a step. I can't get the camera to work once you add the third person controller instead of the character camera script. I have yet to find an actual answer for this.

    Here you stated "If the camera doesn't follow anyone, check "Fight for Control" again and make sure the CharacterCamera gets enabled"

    But int he tutorial it says: "As we don't use CharacterControl and CharacterCamera anymore, remove their enabling-code from RandomMatchmaker.OnJoinedRoom. Both components stay inactive now (they could be removed, too)."

    So...?
     
    Last edited: Jan 25, 2015
  4. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    I will have to update that part. I hope I can find some time to redo the whole thing.

    The idea is: You make the cam NOT follow anything first. Then, when you Instantiate your character, also assign it as target for the cam. You don't sync this, as the cam is only locally following your local character.
    Make sure no script on the character prefab is grabbing control of the cam. Or at least make sure that those scripts only do this when photonView.isMine is true on that GameObject! You have to keep in mind that the prefab is the base for all characters - remote or local.
    Apply the same logic which is explained for input.
     
  5. Khyrid

    Khyrid

    Joined:
    Oct 8, 2010
    Posts:
    1,790
    Yeah... it's just that a third person camera system is kind of a complex thing, or it can be anyway. We disabled our only 3rd person camera script (which was reliant on the third person controller that I think we also disabled).

    I currently switched over to that FPS multiplayer PUN tutorial for now, but third person is my goal, I'll figure this all out at some point.
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    Hm. There is no 3rd person cam script hat runs without the 3rd person controller?
    I will keep that in mind when we have some time to do demos again - but I can't promise anything with a timing...
     
  7. jcbhmmn

    jcbhmmn

    Joined:
    Oct 4, 2014
    Posts:
    21
    Hi Tobiass,

    Does this mean that you are supposed to ignore this statement in the tutorial:
    "As we don't use CharacterControl and CharacterCamera anymore, remove their enabling-code from RandomMatchmaker.OnJoinedRoom. Both components stay inactive now (they could be removed, too)." ?

    I have added the CharacterCamera
    Code (CSharp):
    1.     void OnJoinedRoom()
    2.     {
    3.         GameObject monster = PhotonNetwork.Instantiate("monsterprefab", Vector3.zero, Quaternion.identity, 0);
    4.         monster.GetComponent<myThirdPersonController>().isControllable = true;
    5.         CharacterCamera camera = monster.GetComponent<CharacterCamera>();
    6.         camera.enabled = true;
    7.     }
    part back and the camera seems to be working fine for both clients except for a strange jitter when the monster is turning...

    I am also having a difficult time getting the attack animation to render in both clients. I am able to get the Character State to update with "attacking" for each client, but the animation does not play in the secondary client. Any ideas what I need to do on this?
    Last question is: Do you supply the completed scripts for the Marco Polo tutorial so that I can check to see what I may be doing wrong?

    Best Regards,
    Jacob
     
  8. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,072
    The completed Marco Polo Tutorial is in the PUN package.
    It's a bit different from the tutorial for organizational reasons. And it seems to skip the topic of camera movement alltogether.

    If your camera is jittering when you rotate, then it is highly likely it's affected by two conflicting sorts of input / updates.
    I would have to check the details of the tutorial and the (old-ish) Monster package content, to say more. Let me know if you can't make it work.

    I think I remember that each animation is played back by deliberately activating it via code.
    You need to do the same for the attack.
    You can trigger it in the code of the "attack" RPC method, for all clients (no matter if isMine or not).

    I know it's vague but it's been a while since I revisited the Marco Polo Tutorial and actually, I would like to do a new one since ages.
    I hope this gives you a direction nonetheless.