• Hey! Guest! The 40th (!!!) GMC Jam will take place between February 25th, 12:00 UTC to March 1st 12:00 UTC. Why not join in this very special anniversary jam! Click here to find out more!

GMS 2.3+ How to move path x and y to mouse x and y?

mikix

Member
So I have a circle with straight lines as the connection kind. I want to move this when I press CTRL + SHIFT and it must move to the direction where I am pointing at with my mouse. How do I do this in an easy way? What I mean is I don't want the path pre-assigned to the place I have drawn it on in the path editor, I want to manually move all connections to a desired place, which is, the mouse pointer.
 

TheouAegis

Member
path_shift() will move the path by a specified amount (not to specified coordinates) using point 0 as the reference. If your path is closed and you want the "middle" to move to the mouse, you will need to find the x and y offsets from point 0 to the ml"middle".

Note this affects the path resource itself. I think GM duplicates the path data, or used to, because you will need to stop and restart the path to have it take effect for an instance.
 

Padouk

Member
Have a look at the path and motion planning api
Depending if you want to avoid obstacle or move in straight line you will want to create and assign a path to your object

GML:
var path_id = path_add();
path_add(path, x, y);
path_add(path, mouse_x, mouse_y);
path_set_closed(index, true);
path_start(path, 3, path_action_stop , true);

GML:
var path_id = path_add();
mp_potential_path(path, mouse_x, mouse_y, 3, 4, 0);
path_start(path, 3, path_action_stop , true);
 
Top