title: Raycasts in unity2D
body: <p>I am trying to create a script that will make a game object move along a raycast when it detects something, and for some reason, something in 3d is happening and messing up the raycasts direction</p>
  <p>'''</p>
  <pre><code>using UnityEngine;
  
  public class CreatureActivity : MonoBehaviour
  {
      float sense = 2;
      float speed = .05f;
      LayerMask LayerMask = 8;
  
      private void Start()
      {
          Physics2D.queriesStartInColliders = false;
      }
  
      // Update is called once per frame
      void FixedUpdate()
      {
          Vector2 position = new Vector2(transform.position.x, transform.position.y);
  
          Vector2 right = new Vector2(position.x + 1, position.y);
          Vector2 left = new Vector2(position.x - 1, position.y);
          Vector2 up = new Vector2(position.x, position.y + 1);
          Vector2 down = new Vector2(position.x, position.y - 1);
  
          RaycastHit2D hitInfoR = Physics2D.Raycast(position, right, sense);
          RaycastHit2D hitInfoL = Physics2D.Raycast(position, left, sense);
          RaycastHit2D hitInfoU = Physics2D.Raycast(position, up, sense);
          RaycastHit2D hitInfoD = Physics2D.Raycast(position, down, sense);
          //right ray
          if (hitInfoR.collider != null)
          {
              transform.position = Vector2.MoveTowards(transform.position, right, speed);
              Debug.DrawLine(position, hitInfoR.point, Color.red);
          }
          else
          {
              Debug.DrawLine(position, position + right * 2, Color.green);
          }
          
          //left ray
          if (hitInfoL.collider != null)
          {
              transform.position = Vector2.MoveTowards(position, left, speed);
              Debug.DrawLine(position, hitInfoR.point, Color.red);
          }
          else
          {
              Debug.DrawLine(position, position + left * 2, Color.green);
          }
          //up ray
          if (hitInfoU.collider != null)
          {
              transform.position = Vector2.MoveTowards(position, up, speed);
              Debug.DrawLine(position, hitInfoR.point, Color.red);
          }
          else
          {
              Debug.DrawLine(position, position + up * 2, Color.green);
          }
          //down ray
          if (hitInfoD.collider != null)
          {
              transform.position = Vector2.MoveTowards(position, down, speed);
              Debug.DrawLine(position, hitInfoR.point, Color.red);
          }
          else
          {
              Debug.DrawLine(position, position + down * 2, Color.green);
          }
          
      }
  }
  </code></pre>
  <p>'''
  you can ignore this part stack overflow wants me to add more details but I don't know what else to add.</p>