title: How do I make a object move towards the mouse in p5.js?
body: <p>I'm making a zombie game in p5js, does anyone have any recommendations on to make a shape or object move towards the mouse(this will be used to make the gun)? and if anyone knows how to make more enemies spawn more often each round that would be nice to!:)
  Sorry if the solution is super simple, I still kinda new!</p>
  <p>code:</p>
  <pre><code>let dogmode;
  let round;
  let zombie, player;
  let x, y;
  let health, speed, damage, playerhealth;
  function setup() {
    dogmode=false;
    createCanvas(400,400);
    
    
    round = 1;
    bullet ={
      damage:20
    };
    //Player and zombie parameters
    zombie = {
      pos: createVector(500, 200),
      //increase by 100 each round until round 9
      health: 150,
      speed: 1,
    
    };
    player = {
      pos: createVector(200, 200),
  
      //default
      health: 100,
    };
  fill(0);
  
     
  }
  
    
  function draw() {
    if( dogmode===true){
      player.health=player.health+100;
      
    }
    background(220);
  
    stroke(0);
    
    line(player.pos.x,player.pos.y,mouseX,mouseY);
    fill('gray')
    ellipse(mouseX,mouseY,10,10);  
    push();
    //player
    fill(&quot;green&quot;);
    ellipse(player.pos.x, player.pos.y, 20, 20);
    //HUD or something
    fill(&quot;black&quot;);
    text(&quot;&quot; + player.health, 10, 10);
    //zombie(s)
    fill(&quot;gray&quot;);
    rect(zombie.pos.x, zombie.pos.y, 20, 20);
    //Damage system
    if (p5.Vector.sub(player.pos, zombie.pos).mag() &lt;= 30) {
  
      player.health = player.health - 1;
  
    }
    
    //Health detection
    if (player.health &lt;= 0) {
      background(0);
      textSize(20);
      text(&quot;You died \n Round &quot; + round, 165, 200);
    }
    
    if (keyIsDown(87)) {
      player.pos.y -= 2;
  
    }
    if (keyIsDown(83)) {
      player.pos.y += 2;
  
    }
    if (keyIsDown(65)) {
  
      player.pos.x -= 2;
    }
    if (keyIsDown(68)) {
  
      player.pos.x += 2;
    }
  
    zombie.pos.add(p5.Vector.sub(player.pos, zombie.pos).limit(zombie.speed))
    pop();
  //Create bullet
    if(mouseIsPressed ){
    fill('yellow')
    ellipse(mouseX,mouseY,5,5);
    //Shoots bullet
  }
    
  }
  </code></pre>