Search Unity

Third Party Car Racing game and Photon

Discussion in 'Multiplayer' started by ArtisV, Sep 20, 2013.

  1. ArtisV

    ArtisV

    Joined:
    Jun 25, 2013
    Posts:
    9
    Hello!

    I have car racing game in development. I want to adapt multiplayer feature to my game. Now I have my car as a prefab and the car is spawned as a clone. My car prefab contains PhotonView(script) and in the observe field I have putted my cars prefab transform. The networking is working, I can get two clones driving. The problem is that the player wont see other players wheels visualy spin and wont see visualy stear when the car is turning. How to achieve that wheels are spinning and turning (stearing) ? My car prefab contains children which are car chassis object, all wheel objects, colliders. I tryed to add PhotonView to wheels but nothing change. Maybe thats becouse I added the PhotonView to the children, but the whole prefab PhotonView overrides other children PhotonViews ?


    ThankYou!
    Artis.
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    I guess you send the velocity of the cars?

    Based on that you should be able tell how fast the wheels should be spinning. You could send the rotation of the wheels with your updates and then interpolate them locally.
    Overall send the information needed and then handle it locally.
     
  3. ArtisV

    ArtisV

    Joined:
    Jun 25, 2013
    Posts:
    9
    How to correctly get stream from PhotonVIew which is added to Wheels ? I now have this script added to wheels, but no rotation is being sent over the network. Maybe I dont understand correctly do I need Quaternion or some additional function ?

    Thanks!

    Code (csharp):
    1.    
    2. void Start(){
    3.        pv = GetComponent<PhotonView>();
    4. }
    5.    
    6.     public void OnPhotonSerializeView(PhotonStream stream, PhotonMessageInfo info)
    7.     {
    8.         //we are reicieving data
    9.         if (stream.isReading)
    10.         {
    11.                 //receive the next data from the stream and set it to the truLoc varible
    12.                 if(!pv.isMine){
    13.  
    14.                 trueRot = (Quaternion)stream.ReceiveNext();
    15.    
    16.                }
    17.  
    18.         }
    19.         //we need to send our data
    20.         else
    21.         {
    22.  
    23.                 //send our posistion in the data stream
    24.                 if(pv.isMine){
    25.      
    26.                  stream.SendNext(transform.rotation);
    27.                
    28.                 }
    29.  
    30.         }
    31.  
    32.     }
    33.    
    34.     void Update()
    35.     {
    36.             if(!pv.isMine){
    37.  
    38.             transform.rotation = Quaternion.Lerp(transform.rotation, trueRot, Time.deltaTime * 9);
    39.            
    40.             }
    41.  
    42. }
    43. }