Viking Demo - sending other data

Hello,

Eventually I want to give this a shot - "Melee Fighting" with the Viking demo.

I believe that in order to make this happen properly I need to redesign the OnPhotonSerializeView code below:

ThirdPersonNetworkVik.cs ( Line 39 )
void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    {
        if (stream.isWriting)
        {
            //We own this player: send the others our data
           // stream.SendNext((int)controllerScript._characterState);
            stream.SendNext(transform.position);
            stream.SendNext(transform.rotation);
            stream.SendNext(rigidbody.velocity); 

        }
        else
        {
            //Network player, receive data
            //controllerScript._characterState = (CharacterState)(int)stream.ReceiveNext();
            correctPlayerPos = (Vector3)stream.ReceiveNext();
            correctPlayerRot = (Quaternion)stream.ReceiveNext();
            rigidbody.velocity = (Vector3)stream.ReceiveNext();
        }
    }

My question is would I need to strip away the "Stream.SendNext" idea and convert this code to something that uses Operations and Events as outlined in this tutorial?
http://doc.exitgames.com/v3/quickstart/helloworldpart2

So that I can send other data, besides just movement, whether or not the character is attacking etc. Would anyone have an idea as to the first step? Already have the animations, raycasting, and local photon server setup. I want tell the server there was a "Hit" with my melee weapon.

Thanks for the assist.

-T

Comments

  • You cross posted this on the Unity Forum and I initially answered there.
    But: Lets keep the discussion / further questions here. Thanks.

    There's so many options to do this.
    You could strip away the info you don't need and add the info you want in that stream. The PhotonStream is not limited to positional data. Add info about the key-states and read it below to replicate another user's state.
    You can also use RPCs to hit someone. Photon Unity Networking (which you are using here) is handling the networking and calls the method you called on the remote client.
    This will tell the other players that someone was hit.

    If you need / want more control on the server side, then you will have to dive into Operations and Events. This is what our Photon framework consists of. Operations are RPCs which are only available on the server. You make it do something. Events are sent to the client(s) and carry some info.
    You could add the player or room classes to know the hitpoints per player and add a operation "hit". Calling that new operation will inform the server someone was hit. Then the server has to update players by events.

    PUN is using these operations internally and adds the abilities that Unity Networking offers by using Operations and Events. You can access those by using the PhotonNetwork.networkingPeer direcly. Then you could either extend PUN with your own operations or you could skip PUN and base everything you do on the "plain" API of the Unity3d Photon Client SDK. Get it from our page.
  • Tobias wrote:
    If you need / want more control on the server side, then you will have to dive into Operations and Events. This is what our Photon framework consists of. Operations are RPCs which are only available on the server. You make it do something. Events are sent to the client(s) and carry some info.
    You could add the player or room classes to know the hitpoints per player and add a operation "hit". Calling that new operation will inform the server someone was hit. Then the server has to update players by events.

    PUN is using these operations internally and adds the abilities that Unity Networking offers by using Operations and Events. You can access those by using the PhotonNetwork.networkingPeer direcly. Then you could either extend PUN with your own operations or you could skip PUN and base everything you do on the "plain" API of the Unity3d Photon Client SDK. Get it from our page.

    That's just too general of an answer. The viking demo already has the Photon-Unity Networking Tool and appears to have everything already setup to talk to a local photon server (and it does perfectly). But we need a demo of how to use Events and Operations with a local photon server. I'm assuming the Photon Bootcamp Demo is exactly the same -- designed only to run client side code.

    Tobias, we need a clearer example of how to use Operations and Events, kudos if you can showcase this with the Viking demo.

    No, the MMO demo won't do the trick, the documentation just isn't clear, and the project has bugs (sometimes created during the initial setup process).

    Can you make the modifications to the Viking demo?

    -T
  • I know my answer was general but the question was too broad, too ;)

    The PUN based demos are geared towards using Photon out of the box with Unity-like features and no custom server logic. Because of this, they are not great samples for custom operations. Neither is the Bootcamp Demo.

    There is a Hello World tutorial on our docs pages, which shows how to start from zero and how to implement operations client and server side.
    http://doc.exitgames.com/v3/quickstart/helloworldpart1

    This should get you going, even if it doesn't use PUN.
    As said, in Photon Unity Networking, you call custom operations via PhotonNetwork.networkingPeer. And your server application should be extending the "LoadBalancing" Game Server project.
  • For events there is also no server side involved. Events are just sent and routed through, only Operations are for server side executions and compared to the triviality of the client side stuff, they are much more complex and on top of that, completely different on each of the 3 example photon applications (Lite+Lobby, MMO, LoadBalancing) offered and might be even more different in anything you implement yourself if you do an own custom Photon application :)