Calculates a path between two points, avoiding instances along the way.


mp_potential_path(path, xgoal, ygoal, stepsize, factor, checkall)

Argument Description
path index of the path that is to be used by the function
xgoal The target x position.
ygoal The target y position.
stepsize The speed the instance moves in pixels per step.
factor This number is used to prevent an infinite loop. It should be larger than 1. See the function description for more information.
checkall Whether to check all instances (true) or just solid ones (false).

Returns: Boolean.


This function computes a path for the instance from its current position and orientation to the position specified by the xgoal,ygoal arguments. It uses the indicated step size while trying to avoid collision with either all instances or only those flagged as solid. Like in the function mp_potential_step it uses potential field steps to accomplish this and the manner in which it does this can be modified through the function mp_potential_settings. The indicated path must already exist and it will be overwritten by the new path. The function will return whether a path was found (true) or not (false).

To avoid the function continuing to compute forever you need to provide a factor of larger than 1 - the function will stop and report failure if it cannot find a path shorter than this factor times the distance between start and goal. A factor of 4 is normally good enough but if you expect long detours you might make it longer. If it fails a path is still created that runs in the approximate direction of the goal but it will not reach it.

Note: This function does not move the instance. It sets a path only, and you must use the Path functions for movement.


path = path_add();
mp_potential_path(path, obj_Player.x, obj_Player.y, 3, 4, 0);
path_start(path, 3, 0, 0);

The above code creates a new path resource and stores its index in the variable "path". It then generates a path using mp_potential_path between the object with this code and the object "obj_Player", checking for collisions with all instances in the room. Finally it starts the object along that path, even if the function has failed to return a complete route to the "obj_Player".

Back: Motion Planning
Next: mp_potential_path_object
© Copyright YoYo Games Ltd. 2015 All Rights Reserved