title: Unity networking mouse position
body: <p>I was following <a href="https://docs.unity3d.com/Manual/UNetSetup.html" rel="nofollow noreferrer">this</a> tutorial on the Unity docs, but wanted to change my version to fire towards the mouse position. The host works fine but when running the client the bullets fire towards the mouse position relative to the host client (usually just off to the side).</p>
  
  <p>Here is my code as is:</p>
  
  <pre class="lang-c# prettyprint-override"><code>public class PlayerMove : NetworkBehaviour {
  
      public GameObject bulletPrefab;
  
      // Use this for initialization
      void Start () {
  
      }
  
      // Update is called once per frame
      void Update () {
  
          if (!isLocalPlayer)
              return;
  
          var x = Input.GetAxis("Horizontal") * 0.1f;
          var z = Input.GetAxis("Vertical") * 0.1f;
  
          transform.Translate(x, 0, z);
  
          if (Input.GetMouseButtonDown(0))
          {
              CmdFire();
          }
      }
  
      public override void OnStartLocalPlayer()
      {
          GetComponent&lt;MeshRenderer&gt;().material.color = Color.red;
      }
  
      [Command]
      void CmdFire()
      {
          // create the bullet object from the bullet prefab
  
          // make the bullet move away in front of the player
          Vector2 target = Camera.main.ScreenToWorldPoint(new Vector2(Input.mousePosition.x, Input.mousePosition.y));
          Vector2 myPos = new Vector2(transform.position.x, transform.position.y + 1);
          Vector2 direction = target - myPos;
          GameObject projectile = (GameObject)Instantiate(bulletPrefab, myPos, transform.rotation);
          projectile.GetComponent&lt;Rigidbody2D&gt;().velocity = direction * 4f;
  
          // spawn the bullet on the clients
          NetworkServer.Spawn(projectile);
  
          // make bullet disappear after 2 seconds
          Destroy(projectile, 2.0f);
      }
  }
  </code></pre>
  
  <p>I have also tried to move the "velocity = direction" to a new bullet script but it always performs the same.</p>
  
  <p>How can I use a 'local' mouse position, if that's the solution here?</p>