Search Unity

Third Party Photon Networking "PhotonView.IsMine" Doesn't work right!

Discussion in 'Multiplayer' started by TheBox101, May 11, 2018.

  1. TheBox101

    TheBox101

    Joined:
    Apr 29, 2018
    Posts:
    6
    So I am creating to 2d shooting game and I am in the early stages of game mechanics. I have a PhotonView on my player prefab. For movement I am calling this bit of code in Update:
    Code (CSharp):
    1. if (photonView.isMine) {
    2.     checkInput();
    3. } else {
    4.     smoothNetMovement();
    5. }
    ckeckInput is this:
    Code (CSharp):
    1. private void checkInput()
    2. {
    3.     var move = new Vector3 (Input.GetAxis("Horizontal"), Input.GetAxis("Vertical"));
    4.     transform.position += move * moveSpeed * Time.deltaTime;
    5. }
    And SmoothNetMovement is this:
    Code (CSharp):
    1. private void smoothNetMovement()
    2. {
    3.     transform.position = Vector3.Lerp(transform.position, selfPos, Time.deltaTime * 8);
    4. }
    Sorry for the rambling. But here is the problem, when there is only one player the movement controls are fine. But when there are 2 players (I have only tested up to 2) the movement controls got to the other player. The movement is synced also. So if I use the WASD keys on one player it will control the other player and the camera stays on the correct player. Same for the other player. So each player can control the other player but not themselves. Any help would be appreciated, I have been trying to figure this out for a few days now.
     
    darshan-kirubakaran likes this.
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    The PhotonView.isMine should work, provided that each player creates his own character using PhotonNetwork.Instantiate.
    I can't see where selfPos is coming from.
    If you're using a prefab with a PhotonView on it, make sure it has a component of that prefab in the "observed" field.
     
  3. trentonapplesmyth

    trentonapplesmyth

    Joined:
    Apr 8, 2020
    Posts:
    1
    Hi, I am having this same issue, and they are definitely using observing themself. I have been viewing forums for 2 days now, without any solution. Please help!

    UPDATE:


    Follow the tutorial there. Disable everything you only want on individual players, and enable them when the player is instantiated. Fixed my issue
     
    Last edited: Apr 9, 2020
    darshan-kirubakaran likes this.
  4. mario_code4ever

    mario_code4ever

    Joined:
    Jan 9, 2020
    Posts:
    36
    I cant see an video it shows error can you link it again please
     
  5. Tech_Bud

    Tech_Bud

    Joined:
    Jun 24, 2020
    Posts:
    18
    Have you found a solution to the problem yet?
     
  6. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    3,066
    Describe your issue in a new thread. This thread is more than 2 years old and the solutions from that time are not the same today.
     
  7. Lastered

    Lastered

    Joined:
    May 13, 2021
    Posts:
    2
    A little late, but I believe that photonView.IsMine has a capital "i" and "m"
    At least that's what worked for me :)