1

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.

thank you in advance for your help.

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


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??

  • the OncollisionEnter is on the player script – Romain karawani Jan 02 '19 at 18:45
  • Probably related or even a duplicate: https://stackoverflow.com/q/44266691/7111561 – derHugo Jan 03 '19 at 06:18
  • If it's something like the bullet is moving too fast to handle the collision consider skipping collision and doing a raycasts between last frame's bullet position & new frame bullet position and scan for hits between them. – Fredrik Schön Jan 03 '19 at 09:40

0 Answers0