Finding the next closest viable path

S

squirrelah

Guest
So i am tryign to make a game where characters are moving along the path using the path function.

But there are also objects the players can place down. Currently i have it so if a character is moving, and an object being placed keeps them from getting to point X(as in there is no viable path to get there), the path just ends where they are.

So basically it's like this

Player start----------Player End--------------------building placed----------------destination

and i want it to be like this


Player start-----------------------------Player End-Building placed------------------destination.



I already figured out how to get it to go around the building if its placed while they are moving, but i basically need to know how to make it so when there isn't a viable path, to make a viable path that's at least semi-close to the building that blocked their path.

Im currently using if( mp_grid_path(grid,regular_movement,x,y,x1,y1,true))
{
path_start(regular_movement,pathspeed,path_action,false)
}

as the way to figure out if a path is viable/to start a path.
 
Last edited by a moderator:
S

spoonsinbunnies

Guest
when anyone sets a block
Code:
global.lastblock=id
when pathfinding
Code:
if!( mp_grid_path(grid,regular_movement,x,y,x1,y1,true))//if cant reach the player
{
x1=global.lastblock.x//set the last block placed as the goal
y1=global.lastblock.y
do
{
x1+=lengthdir_x(1,point_direction(x1,y1,x,y))//loop to move out of the box torwards the player
y1+=lengthdir_y(1,point_direction(x1,y1,x,y))
}}
until mp_grid_path(grid,regular_movement,x,y,x1,y1,true)= true//until a viable path is found
path_start(regular_movement,pathspeed,path_action,false)//start the path
 
S

squirrelah

Guest
when anyone sets a block
Code:
global.lastblock=id
when pathfinding
Code:
if!( mp_grid_path(grid,regular_movement,x,y,x1,y1,true))//if cant reach the player
{
x1=global.lastblock.x//set the last block placed as the goal
y1=global.lastblock.y
do
{
x1+=lengthdir_x(1,point_direction(x1,y1,x,y))//loop to move out of the box torwards the player
y1+=lengthdir_y(1,point_direction(x1,y1,x,y))
}}
until mp_grid_path(grid,regular_movement,x,y,x1,y1,true)= true//until a viable path is found
path_start(regular_movement,pathspeed,path_action,false)//start the path

thank you that worked perfectly.
 
Top