Search Unity

multiplayer collision problem

Discussion in 'Physics' started by romain1994, Jan 1, 2019.

  1. romain1994

    romain1994

    Joined:
    Oct 23, 2018
    Posts:
    26
    hello i am building a multiplayer game, and i have a problem with my client receiving information when he gets shot.
    i made a script that i attached to the player,

    void OnCollisionEnter(Collision coll)
    {

    if (isLocalPlayer) {
    if (coll.gameObject.tag == "bullet") {
    Debug.Log ("hit");
    isHit = true;

    }
    }
    }

    when i am on the host, everything works perfectly and every time i hit the host, i can see the debug.log in the inspector.
    but when i am on the client. the debug.log is not accurate the client only receives the information like 1/3 of the time, sometime it works sometime it doesn't. its like sometime the client doesn't find the gameobject tagged "bullet". Anyone got the same issue or knows how to fix that??

    btw i spawn my bullet with the following code:

    [Command]
    void CmdShoot()
    {
    GameObject bullet = (GameObject)Instantiate (_bulletPrefab, _canon.position, _canon.rotation);
    bullet.GetComponent<Rigidbody> ().velocity = bullet.transform.forward * _bulletSpeed;
    NetworkServer.Spawn (bullet);
    }
    thank you in advance for your help.