Change path of an object at a point

S

samyak

Guest
An object is moving on a path0. There is another path 'path1' close to path0 at x=a; y=b. How to change the path of the object from path0 to path1 at (a,b) ?
 

icuurd12b42

TMC Founder
GMC Elder
you been to find the closest point_line_distance on path1

for this you will need to loop through the path1
call to get a start and end of a path line small enough
path_get_x(ind, pos);
path_get_y(ind, pos);

note that pos is a 0 to 1 value that 0 to 1 so you will need to loop from 0 to 1-somefraction, each step of of say somefraction and get point1 at i
mind = 1000000;
dist_along_line = 0;
posi = 0;
for(i=0;i<=1-.1;i+=.1)
{
x1 = path_get_x(path1,i);
y1 = path_get_y(path1,i);
x2 = path_get_x(path1,i+.1);
y2 = path_get_y(path1,i+.1);
d = point_line_distance(x,y,x1,y1,x2,y2,1);
if(d<mind)
{
mind=d;
posi = i;
dist_along_line = point_distance(x1,y1,x0,y0);
}
}
you will need to path_start with path1 and then set path_position manually to set to the right position...
the path_position will need to be set to posi+(dist_along_line/path_get_length(path1)) or something like that. too tired to check if the math is valid. essentially you have the rough fractional position with i, store in posi, the closest found line start... and you need to add another fraction value that matches the distance along the line segment, as a fraction... the distance from the start of the line (dist_along_line, in pixel) over the path_length (in pixel) should do the trick
 
Top