• Hey Guest! Ever feel like entering a Game Jam, but the time limit is always too much pressure? We get it... You lead a hectic life and dedicating 3 whole days to make a game just doesn't work for you! So, why not enter the GMC SLOW JAM? Take your time! Kick back and make your game over 4 months! Interested? Then just click here!

Legacy GM Pathfinding clean collision code...?

A

AtomicToilet

Guest
Hola!

I've had an eyeball at similar queries and understand that, if I want to stop objects overlapping if they use the same path, I need to stop the path and then restart it. The trouble is, I'm not sure how to make this clean so that I don't need different code for each object.

At the moment I have two 'player' objects that can be selected seperately and then told to go wherever. Player 1 has this collision code for player 2:

Code:
path_end()

///Create path for pathfinding
    var nx = obj_player.x + 2;   //(x div 32)*32+16;
    var ny = obj_player.y + 2;   //(y div 32)*32+16;
    
    if (mp_grid_path(global.grid,path,x,y,nx,ny,1))
    {
    path_start(path,3,path_action_stop,false);
    }
Player 2 has this collision code for player 1:

Code:
path_end()

///Create path for pathfinding
    var nx = (mouse_x div 32)*32+16;
    var ny = (mouse_y div 32)*32+16;
    
    if (mp_grid_path(global.grid,path,x,y,nx,ny,1))
    {
    path_start(path,3,path_action_stop,false);
    }
these both work reasonably ok, except there's a chance one object bumps the other into a wall/solid object, which obviously isn't brilliant.

My question is: how can I change the nx / ny variables so that this code can be shared between player controlled objects, without leading to overlapping? ie without both objects, upon collsion, then moving to exactly the same space? And ideally without going into walls! I feel like the answer's going to lead to a facepalm moment because it's so obvious haha
 
Top