title: Problems making enemy follow moving player
body: <p>Okay, so I want to make a javascript/html canvas game where the player is being followed by some enemies, and after a little bit of 'research' her is the most important part of my Monster (enemy) class:</p>
  
  <pre><code>  this.UpdateAngle = function() {
      this.dx = this.x - player.x;
      this.dy = this.y - player.y;
      this.angle = Math.atan2(this.dy, this.dx) * 180 / Math.PI;
      if (this.angle &lt; 0) {
        this.angle += 2 * Math.PI;
      }
    }
    this.UpdateSpeed = function() {
      this.speedX = this.speed * Math.cos(this.angle);
      this.speedY = this.speed * Math.sin(this.angle);
    }
    this.Move = function() {
      this.UpdateAngle();
      this.UpdateSpeed();
      this.x += this.speedX;
      this.y += this.speedY;
    }
  </code></pre>
  
  <p>So what I meant to do here, was to calculate the angle from the enemy to the player with <code>atan2()</code> and then calculate how much I should move in the x and y axis by using <code>cos()</code> and <code>sin()</code>, the speed and the angle I calculated, and then just moved the calculated pixels.</p>
  
  <p>This all seems to work well, until I move the player, then the enemies start to move in weird directions. I have no idea whats wrong, it would be awesome if someone could learn me how this is meant to be done. :D</p>
  
  <p>You can see it in action <a href="http://www.bertramconsulting.dk/Christian/Victor" rel="nofollow">here</a>. *I have updated the code with PremierBromanov's suggestion.</p>