title: How Can I Improve My AI To Not Bounce Back And Forth
body: <p>So I'm using unity3d and I have an AI. It has an invisible rectangle always facing towards a character, if the distance between the AI and the character are less than the max distance AND the invisible rectangle is not touching an obstacle then the AI will chase the character. The AI will continue patrolling if it is touching both at once (player and obstacle). But the problem is that sometimes if the player is in a certain position this happens:</p>
  
  <p>The AI is not touching an obstacle and so the AI moves towards the player. Then the AI touches an obstacle behind him. So he is touching the player and a obstacle and is told to move back. As soon as he moves back a little bit he isn't touching an obstacle and is less than max distance and moves back to the player. This repeats forever giving an annoying continuous loop.</p>
  
  <p>And before you answer to make the rectangle shorter, I need to tell you: I have already tried and the rectangle then doesn't detect all collisions because of the angles the rectangle turns to.</p>
  
  <p>MORE INFORMATION:</p>
  
  <ul>
  <li>The rectangle is always facing the player exactly.</li>
  </ul>
  
  <p>So - how can I fix this? I would really appreciate any answer.</p>