title: How to make one object follow another
body: <p>I am making a game and I have my hero and enemy. Now I want enemy to follow hero when distance between them is 400 for example. 
  How can I make it work.
  Here is what I ve got so far, but it doe not work.
  Objects::calcAngle(Objects* obj) - calculates angle between central points of 2 objects.</p>
  
  <pre><code>float Objects::calcAngle(Objects* obj){
      float dx = obj-&gt;X - this-&gt;X; 
      float dy = obj-&gt;Y - this-&gt;Y;
      float angle=atan(dy/dx)*180/PI;
      return angle;
  }
  
  void Enemy::Attack(mainCar* car){
      float angle=0;
      angle=this-&gt;calcAngle(car);
      if(this-&gt;Distance(car)&lt;400){
          this-&gt;attack=true;
          this-&gt;heading=this-&gt;calcAngle(car)+90; 
          this-&gt;Vtri=abs(this-&gt;Vtri);
      } else if (this-&gt;Distance(car)&gt;400) {
          this-&gt;attack=false;
      }
  }
  </code></pre>
  
  <p>Vtri is speed of movement.
  heading is direction  in degrees.</p>
  
  <p>If you can give me a link to where it is described or just tell me here, it would be great. I have 2 days to submitt my project.</p>