I have 3 points: p1, p2, and p3. I am trying to create a slider effect using p2 and the mouse along a line of any distance and angle as defined by positions of p1 and p3:

* p1 and p3 define the points of a line, and

* p2 should be able to move freely, following the mouse, between p1 and p3,

* p2's movement should be restricted by the length of p1 to p3 and the direction from p1 to p3

(so p2 cannot move beyond the length of the line and must only be moving in the direction of the line).

It is almost working, but it seems my use of point_distance with p1 is incorrect. The distance from p1 to the mouse does not easily reach '0' so p2 does not get to exactly the same position as p1, and distance starts increasing again when the mouse moves away from p1 in a different direction. My goal is to select p2 and, if the mouse moves to p1 or p3 (or beyond either point) it slides and stops at those points.

Here's my code - any ideas?

GML:

```
my_dist = point_distance(p1.x, p1.y, mouse_x, mouse_y);
my_dir = point_direction(p1.x, p1.y, p3.x, p3.y);
ldx = lengthdir_x(my_dist, my_dir);
ldy = lengthdir_y(my_dist, my_dir);
x = p1.x + ldx;
y = p1.y + ldy;
```

Quokka