title: Unity 2D Raycasting from a Rotating Transform
body: <p>I'm trying to create a vision field in Unity 2d. I'm projecting raycasts from a rotating gameobject which rotates according to where the character is looking. However this character moves back and forth so when they are moving left I set the transform.scale to -1. The problem is when I do this the raycasts don't change direction along with the character and stay pointing right! Here is the code, I'm probably missing something obvious! Any help would be appreciated!</p>
  
  <pre><code>        Transform parent;
      float vision_angle_ = 50;
      float direction;
      Vector3 angle;
      Vector2 position;
      Quaternion q;
      int x = 10;
  
      void Start ()
      {
              parent = transform.parent;
      }
  
      void Update ()
      {
  
              direction = parent.GetComponent&lt;Behaviour&gt;().direction;
  
              angle = new Vector2 (x, Mathf.Tan ((vision_angle_) * .5f * Mathf.Deg2Rad) * x);
              q = Quaternion.AngleAxis (1, -transform.forward);       
              position = new Vector2 (transform.position.x, transform.position.y);
  
              for (float i = 0; i &lt; 50; i++) {
                      angle = q * angle;
                      RaycastHit2D tile_hit = Physics2D.Raycast (position, transform.TransformDirection (angle), 10);
                      Debug.DrawRay (position, transform.TransformDirection (angle), Color.green);
              }       
  
      }
  </code></pre>