Search Unity

Third Party (Photon) Instantiating and following Bullets

Discussion in 'Multiplayer' started by RyanPaterson, Jul 30, 2014.

  1. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    Hi,

    I'm tying to use a RPC call to everyone to load the bullet, add the force, and let the collision detection or (timer)on the instantiated object itself delete itself. It works, sort of. It only works well on the host. It can receive the clients bullets paths properly, and its own.

    However, the client will display weirdly, how the attached video shows.

    This is my RPC function:
    This is on a script called 'Player' which is activated on the level load for each player, so that only one instance has it.. so it's not controlling both players.

    Here's a video of the problem (The host is on the right, and is the one i'm controlling)


    Code (csharp):
    1.  
    2.     [RPC]
    3. IEnumeratorFire(Vector3_dir)
    4.  {
    5.  
    6. readytofire = false;
    7.  
    8. GameObject_Bullet = Instantiate (Resources.Load ("Bullet"), transform.position, Quaternion.identity) asGameObject;
    9.  
    10. Physics.IgnoreCollision(this.collider, _Bullet.collider);
    11.  
    12. _Bullet.rigidbody.AddForce (_dir * 700);
    13.  
    14. yieldreturnnewWaitForSeconds(0.06315789473684f);
    15.  
    16. readytofire = true;
    17.  
    18.  }
    19.  



    and this is the script I have on my bullet itself, to follow its position over the network

    Code (csharp):
    1.  
    2.  
    3. Vector3realPosition;
    4.  
    5. voidUpdate()
    6.  {
    7.  
    8. if (photonView.isMine)
    9.  {
    10.  
    11.  } else {
    12.  
    13. transform.position = Vector3.Lerp (transform.position, realPosition, 0.1f);
    14.  
    15.  }
    16.  
    17.  }
    18. publicvoidOnPhotonSerializeView(PhotonStreamstream, PhotonMessageInfoinfo) {
    19.  
    20. Vector3pos = Vector3.zero;
    21.  
    22. if (stream.isWriting) {
    23.  
    24. pos = transform.position;
    25. stream.Serialize(refpos);
    26.  
    27.  } else {
    28.  
    29. stream.Serialize(refpos);
    30. realPosition = pos;
    31.  
    32.  }
    33.  
    34.  }
    35.  

    Really appreciate any help!
    Thanks
     
  2. BFGames

    BFGames

    Joined:
    Oct 2, 2012
    Posts:
    1,543
    Ouch! You should not update bullets over network only instantiate them and then handle them locally! Else you will kill your game :D
     
  3. RyanPaterson

    RyanPaterson

    Joined:
    Dec 14, 2013
    Posts:
    77
    That makes sense I guess! I'll give that a go, cheers