I'm trying to make a program where an object (for now a rectangle) follows and chases the mouse cursor at a constant speed. I've done a quick search and all I seem to find is the code below -
xpos = xpos + (mouseX - xpos)/n;
ypos = ypos + (mouseY - ypos)/n;
The code does chase the mouse but quickly accelarates when far from the cursor and decelarates when close to cursor.