title: Shooting a bullet in front of player C#
body: <p>I'm trying to Instantiate a 'bullet' in front of the player (the gameobject the script is attached to). I tried (as i saw in other threads), but doesnt work:</p>
  
  <pre><code>GameObject  bulletobj = Instantiate (bulletFired, transform.position + transform.forward * 2, Quaternion.identity) as GameObject;
  </code></pre>
  
  <p>The problem is that the bullet has a collider that always hit the player because in a certain rotation the bullet spawns behind the player :/, so i need to spawn it in front of him. This is the lines i made to propulse it:</p>
  
  <pre><code>var mousePosition = FindObjectOfType&lt;Camera&gt; ().ScreenToWorldPoint (new Vector3 (Input.mousePosition.x, Input.mousePosition.y, Input.mousePosition.z - FindObjectOfType&lt;Camera&gt; ().transform.position.z));
  
  bulletobj.GetComponent&lt;Rigidbody2D&gt; ().velocity = (mousePosition - transform.position).normalized * bulletSpeed * Time.smoothDeltaTime;
  </code></pre>
  
  <p>Thanks in advance guys :D</p>