Search Unity

  1. We have added dedicated sub-forums for UNet, the experimental MLAPI and Unity Transport Package. Please use the new forums to discuss related topics.
    Dismiss Notice
  2. How can our website serve you better? Give us your feedback. Take our survey and let us know.
    Dismiss Notice

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

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

  1. nagoL2015

    nagoL2015

    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.
     
  2. tobiass

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    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.
     
    trentonapplesmyth and Ninquiet like this.
  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
  4. mario_code4ever

    mario_code4ever

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

    Tech_Bud

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

    tobiass

    Joined:
    Apr 7, 2009
    Posts:
    2,642
    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.
     
unityunity