Help with chasing the mouse cursor at a constant speed
in
Programming Questions
•
7 months ago
Hello
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 -
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.
Any help will be greatly appreciated.
Thanks
Any help will be greatly appreciated.
Thanks
1