Multiplayer game : bullets spawning and direction point is shows different with each players.

190887-nanada.png

as you can see I am shooting up on my main screen it shows bullets are going up and thats true ,
but on the other screen (other players) see the bullet going different direction.

Related Codes :


 private void Update()
    {
        HandleShooting();
    }

    void HandleShooting()
    {
        if (Input.GetMouseButton(0))
        {
            if(Time.time > shootingTimer)
            {
                shootingTimer = Time.time + shootingTimerLimit;
                //animate muzzle flash
                shootinhAnimation.SetTrigger(TagManager.SHOOT_ANIMATION_PARAMETER);

                //bullet shoot
                CreateBullet();
            }
        }
    }

    private void CreateBullet()
    {
        // playerWeaponManager.Shoot(bulletSpwantPos.position);
        if (!pv.IsMine)
        {
            return;
        }
        else
        {
        pv.RPC("Shoot", RpcTarget.All,bulletSpwantPos.position);
        }
    }

Function that instantiate the bullet


   [PunRPC]
   public void Shoot(Vector3 spawnPos)
   {
       targetPos = mainCam.ScreenToWorldPoint(Input.mousePosition);

       bulletSpawnPosition = new Vector2(spawnPos.x , spawnPos.y);

       direction = (targetPos - bulletSpawnPosition).normalized;

       bulletRotation = Quaternion.Euler(0, 0, Mathf.Atan2(direction.y, direction.x) * Mathf. Rad2Deg);


       if (direction.x < -1 && direction.y > 0)
       {
           BulletPool.instance.FireBullet(weaponIndex, bulletSpawnPostLast[2].position, bulletRotation, direction);
       }

     

       if (direction.x < 1 && direction.y < 1)
       {
           BulletPool.instance.FireBullet(weaponIndex, bulletSpawnPostLast[1].position, bulletRotation, direction);
       }


   }

Well the first thing I can see is that you made the Shoot() a PunRPC and it gets the mouse input, which you should not do in any RPC (generally speaking). Input should be read before it calls any RPC because those will happen on the other machines. The other thing you should think about is whether or not you will enforce some kind of server enforced system, or if you will just trust the clients. You could just let the client’s enforce their own shots with collision and then report the damage. If it’s a fast paced game you could just make the clients RPC shoot the projectile in the direction and have local collision destroy it when it hits something - without resolving any damage. The damage would be resolved either by the server or by the client who fired if you want to trust the clients. In the client auth case, the RPC to other clients would simply mimic what you had fired (assuming there is no physics involved, and the projectile can’t bounce randomly). This makes the networking very light and you can have lots of projectiles going on and exploding (the explosions can even use physics if they are just for visual effect and not for splitting projectiles which can further collide and do damage). A typical scenario where there would only be a few projectiles on screen at a time (including any other player’s projectiles) would be to have the projectile be a networked object and let PUN replicate it and its position and rotation. In that case only one machine will instantiate it.
Also, PUN2 already supports a pool for creating objects. The last option would be consider in your design that the host be the server, and only the host creates the projectile (which is again a networked object).
So these are some things you will want to consider in your design and the choices you have.