Search Unity

Third Party Photon | Questions about Instantiating a GameObject manually, Friend Request and Smooth Movement

Discussion in 'Multiplayer' started by yepfuk, Mar 12, 2017.

  1. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Hi;

    I have a few questions about Photon Networking,

    1- I created a Lobby scene and in this scene, player's can add their friends based on username, and they can see their friend's some informations. The friend system is working perfectly but in this system, player's can add every player without permission. Is there any way to handle sending friend request on Photon? Or I have to handle this myself ?

    2- In my game player's can Instantiate some kind of bullets, and I Instantiate this bullets manually(not using PhotonNetwork.Instantiate) and assign their ViewID's.

    Code (CSharp):
    1. photonView.RPC("Shoot", PhotonTargets.All,shootPosition,shootRotation,PhotonNetwork.AllocateViewID());
    2.  
    3. [PunRPC]
    4. private void Shoot(Vector3 spawnPoint, Quaternion spawnRotation, int id)
    5.     {
    6.         GameObject ball = Instantiate(Ball, spawnPoint, spawnRotation) as GameObject;
    7.         PhotonView[] nViews = ball.GetComponents<PhotonView>();
    8.         nViews[0].viewID = id;
    9.     }
    But sometimes photonView.RPC gives NullReferenceExceptionError , and obviously this causes player's can't instantiate bullet. Why is this happening?

    3- The bullets I mentioned above have PhotonView component, but there is no PhotonTransformView component. Am I need to add this component too and observe this on PhotonView? The bullets moves constant speed and constant route.

    4- Player's movements and animations are not smooth enough. All player's have PhotonView, PhotonAnimatorView and PhotonTransformView. I can't figured it out. I attached my PhotonTransformView settings.

    Thank you in advance...
     

    Attached Files:

  2. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    1. As far as I remember photon has no asynchronous option for friends request. But this can be handled with external dynamic database.

    2. Seems like you are doing something wrong. The weapon shooting logic looks incorrect as well.
    The bullet does not need any photon observation it's already synced by the punRPC.

    4. Make sure you have interpolation selected. The movement should be smooth if not, it's not photons fault. What you can do is increase the photon message send rate: (default is 10 messages/s)
    PhotonNetwork.serializedSendRate, but warning: PUN message limit per room & second is set to 500 messages, so be careful on what you are doing.
     
    yepfuk likes this.
  3. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Thank you,

    1-I already used extrernal server and database to handle friend list, and some information about players. I can add friend request feature, I ask this question just for clerifying.

    2- I will remove the Photon Transform View from the bullets then. But what is wrong with my shooting logic? When the player press the appropriate key the RPC send message to all players, and instantiate the bullet.

    4- I selected the interpolation. But there is not enough documentation about the Photon Transform View, I want to understand what I'm doing. I mean, what is the interpolation and extrapolation, what are the differences, which option is suitible for my game.

    Thank you again.
     
  4. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    You can check and look for unitys interpolation gudie. Interpolation is always good for games that are fast peaced.
    This will prevent lags due to lower network position messages rate.

    Well, why do you try to send the viewID as parameter? Why do you need it? + it's allocate a new viewID not the players ID. Your code confusing me hard and that getcomponent in the rpc... All you need is only spawn the bullet, give shooting info: direction,shootpos etc. If you want more info about the executed RPC then add PhotonMessageInfo as parameter which contains information about the sender of the message.
     
  5. yepfuk

    yepfuk

    Joined:
    Sep 23, 2015
    Posts:
    67
    Thank you again,

    I searched but I didn't found documentation about interpolation settings? Can you send me the link of it?

    I send the viewID because all of the players have to see this bullet, and for this we need to assign it unique viewID to tell the Photon player shoot bullet, don't we?
    In this documentation they explain that under the manual instantiation header I suppose;
    https://doc.photonengine.com/zh-cn/pun/current/manuals-and-demos/instantiation
    Am I understood it wrong?

    Or is this the right way to instantiate objects over network?

    Code (CSharp):
    1. photonView.RPC("Shoot", PhotonTargets.All,shootPosition,shootRotation);
    2. [PunRPC]
    3. private void Shoot(Vector3 spawnPoint, Quaternion spawnRotation)
    4.     {
    5.         GameObject ball = Instantiate(Ball, spawnPoint, spawnRotation) as GameObject;
    6.     }
     
  6. Kamil-Says

    Kamil-Says

    Joined:
    Jun 30, 2014
    Posts:
    154
    It's manually allocated viewID and ONLY for players (in this example). That's a player creation logic and not weapon logic! No extra photon view is needed since the main player view owns and operates all your synced character actions.

    Here is a wiki blog about interpolation: Click Me!

    Yup that looks correct to me :).
     
    tobiass likes this.