title: Raycast at an offset
body: <p>I am trying to make an enemy in my game that can see the light coming from the flashlight of the player. I am doing this by raycasting from the origin of the flashlight towards 5 directions: the middle of the light beam, and the top, bottom, left and right end of the light. Something like this:</p>
  
  <p><a href="https://i.stack.imgur.com/TNOFN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/TNOFN.png" alt=""></a></p>
  
  <p>I use the following update function in the flashlight of the player:</p>
  
  <pre><code>void Update () {
      float angle = GetComponent&lt;Light&gt;().spotAngle;
      if (Physics.Raycast (transform.position, transform.forward, out hitMiddle)){
          hitMiddlePosition = hitMiddle.transform.position;
      }
      if (Physics.Raycast (transform.position, Quaternion.AngleAxis(-angle, transform.up) * transform.forward, out hitDown)){
          hitDownPosition = hitDown.transform.position;
      }
      if (Physics.Raycast (transform.position, Quaternion.AngleAxis(angle,transform.up) * transform.forward, out hitUp)){
          hitUpPosition = hitUp.transform.position;
      }
      if (Physics.Raycast (transform.position, Quaternion.AngleAxis (angle,transform.right) * transform.forward, out hitRight)){
          hitRightPosition = hitRight.transform.position;
      }
      if (Physics.Raycast (transform.position, Quaternion.AngleAxis (-angle, transform.right) * transform.forward, out hitLeft)){
          hitLeftPosition = hitLeft.transform.position;
      }
  }
  </code></pre>
  
  <p>This code is supposed to track the location of each of the hits. However, the locations never seem to correspond to the locations the light beam is hitting. The locations usually are identical in all directions (Vector3(-87.77855, 0, 87.83269))  and do not change when the player is moving. Looking in different directions sometimes changes one of the values.</p>
  
  <p>I tried a lot of different ways of the direction for the raycasts, but I am still not very confident the rays are being cast in the direction I intended.</p>
  
  <p>Any tips?</p>
  
  <p>Many thanks!</p>