Search Unity

rpc functions

Discussion in 'Multiplayer' started by yogeez, Oct 12, 2009.

  1. yogeez

    yogeez

    Joined:
    Mar 4, 2009
    Posts:
    129
    hi,
    in the process of making a character movement in network wise manner.
    Using RPC for the functions of movements and different actions, so the query is,,, will there be have to add @RPC functional behavior in every script files to all the funtions and network view component on all the gameobjects (still this is not done by me) OR is there any other way that i should know about.

    Example : Like directly making the camera in network view manner and with single RPC funciton to draw the whole game to work in a networking manner with the position movement actions and all events synch ?

    It will be good if i am given a simple answer instead of given reference towards the network example
     
  2. INSANE_BR

    INSANE_BR

    Joined:
    Sep 10, 2009
    Posts:
    142
    Hmmm I'm not sure if I understand your problem, but lets try.

    Every function that you will call vai RPC, has to have @RPC before the declaration of the function. Example:

    Code (csharp):
    1.  
    2. function callRPC():void{
    3.  networkView.RPC("GoRPC",RPCMode.Server,"Hello World");
    4. }
    5.  
    6. @RPC
    7. function GoRPC(pMsg:String):void{
    8.  Debug.Log(pMsg);
    9. }
    10.  
    11.  
    With this code, all clients that call the function 'callRPC' will send a "Hello World" to the server.

    If you need your server to send back some info:


    Code (csharp):
    1.  
    2. function callRPC():void{
    3.  networkView.RPC("GoRPC",RPCMode.Server,"Hello World");
    4. }
    5.  
    6. @RPC
    7. function GoRPC(pMsg:String):void{
    8.  Debug.Log(pMsg);
    9.  networkView.RPC("Info",RPCMode.Others,"Hello Client");
    10. }
    11.  
    12. @RPC
    13. function Info(pInfo:String):void{
    14.   Debug.Log("Info = " + pInfo);
    15. }
    16.  
    17.  
    This way, your clients send inputs to the server and the server send back results. This simple model can be applied for character movement also, althought I suggest you use a networkview with state synchronization and interpolation/extrapolation code (from examples).

    I hope I have helped.[/code][/quote]
     
  3. yogeez

    yogeez

    Joined:
    Mar 4, 2009
    Posts:
    129
    yaa thanks beneton.
    Got your point. I already worked out in the same manner too, its working too. but there is lag in movement update and while making movement, rotation of gameobject and animations all in a separate rpc. Donno its the proper way.

    As i did that way only. And now thinking to go for state synchronization with serialize network view. its the method used in the network example of car driven on a terrain.

    so should go for this instead of RPC.
     
  4. INSANE_BR

    INSANE_BR

    Joined:
    Sep 10, 2009
    Posts:
    142
    Yeah, I would go for state synchronization. And make sure you use some Interpolation/Extrapolation code. This way the movements and rotations won't me laggy.

    If you are using Authorative server (as I think you are) make sure you use some Prediction code also, so the clients can feel a slow response from their input.

    :)