title: Raycasting for a third person shooter
body: <p>I need to do a raycast from my player character, to the hit object of my camera raycast but I cant get my code to work, it always seems offset.</p>
  
  <pre><code>        void Update () {
  
      RaycastHit hit;
      Ray playerAim = playerCamera.GetComponent &lt; Camera &gt; ().ScreenPointToRay(new Vector3(Screen.width / 2, Screen.height / 2 ));
      Physics.Raycast(playerAim, out hit);
      Debug.DrawRay(playerAim.origin, playerAim.direction * hit.distance, Color.green);
  
      if (Physics.Raycast(playerAim, out hit)){
          // something was hit
          RaycastHit playerHit;
          Physics.Raycast(transform.position, hit.transform.position,  out playerHit);
          Debug.DrawRay(transform.position, playerHit.transform.position, Color.red);
  
          Debug.Log ("Distance from camera: "+ hit.distance);
          Debug.Log ("Distance from player: "+ playerHit.distance);
      }
  }
  </code></pre>
  
  <p><a href="http://i.stack.imgur.com/HzdVU.jpg" rel="nofollow">http://i.stack.imgur.com/HzdVU.jpg</a></p>
  
  <p>I thought <code>Debug.DrawRay(transform.position, playerHit.transform.position, Color.red);</code> should draw a red line from my player to the end of the green line the cameras hit point, instead it shoots past into the floor.</p>