title: Unity|Moving gameobjects away from other gameobjects which are moving towards them
body: <p>I have 2 AI game objects which are both capsules. Considering the first capsule AI is named X and the second capsule AI is named Y, I try to make Y move away from X (escape from him) while X is chasing Y (following him). I have no idea how to do that, I would appreciate a direction.</p>
  
  <p>I tried to do what's written here, but they both move through walls even though they have capsule collider, I tried to do this: </p>
  
  <p><a href="http://forum.unity3d.com/threads/getting-objects-to-move-away-from-my-users-gameobject.142468/" rel="nofollow noreferrer">http://forum.unity3d.com/threads/getting-objects-to-move-away-from-my-users-gameobject.142468/</a></p>
  
  <p>but they only move in one direction and through walls.</p>
  
  <pre><code>Vector3 position = transform.position;
  Vector3 targetPosition = target.transform.position;
  Vector3 direction = position - targetPosition;
  transform.position += direction * 2.0f * Time.deltaTime;`
  </code></pre>