• 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!

GML Pathfinding with minimal number of enemies causing slowdown

Cpaz

Member
Recently, I've been putting together a better system of pathfinding. Now that it works, I need it to run well with a decent number of enemies.

The path is defined the the create event of the parent object as so:
Code:
///collision testing
path=path_add();
The "end step" event handles the use of the path found and detects if the is a path:
Code:
//DEFAULT MOVEMENT
        if !custommov{//default movement
            if distance_to_object(in)>chdist{ //"Gotta get closer!"
                if mp_potential_path_object(path,inx,iny,sp/delta,2,obj_solid){
                    path_start(path,sp/delta,path_action_stop,true);
                    can_at=false;
                }
                else{
                    if alarm[6]=-1
                        alarm[6]=(90+irandom(90))*delta;
                       //basically means 2 second plus a random number between 2 seconds
                }
            }
            if distance_to_object(in)<=chdist{ //"Too close."
                path_end();
                speed=0;
                can_at=true;
            }
        }
Then there is the alarm referenced in the above snippet:
Code:
///set path
path_clear_points(path);
mp_potential_path_object(path,inx,iny,sp/delta,2,obj_solid);
This is all very basic, but in practice, I cannot have 10 enemies on screen and have above ~10FPS (it ranges from 30-120 by manual settings)
Is there something I'm missing in setting this up?
 

TheouAegis

Member
Probably running mp_potential_path_object() every step. Maybe only rewrite the path when can_at is true or in the alarm.
 

Nocturne

Friendly Tyrant
Forum Staff
Admin
It doesn't need to check the path every step. Set it to check the path in an alarm and set the alarm initially to a random time 8and then a fixed time thrreafter) to stagger the load too. SO like, in the create event you'd have:

alarm[0] = 1 + random(room_speed);
Then in the alarm event:

alarm[0] = room_speed;
// your path code here
You can even use this to create a basic level system for the enemies, as a faster alarm update speed will give a more "intelligent" or harder enemy, while a slower one will make them "dumber" and easier. ;)

Also, I would really suggest against the mp_potential functions as they are very slow. If you want a path, then use the mp_grid functions instead. they are faster and will give the same, if not better, results.
 

Cpaz

Member
It doesn't need to check the path every step. Set it to check the path in an alarm and set the alarm initially to a random time 8and then a fixed time thrreafter) to stagger the load too. SO like, in the create event you'd have:



Then in the alarm event:



You can even use this to create a basic level system for the enemies, as a faster alarm update speed will give a more "intelligent" or harder enemy, while a slower one will make them "dumber" and easier. ;)

Also, I would really suggest against the mp_potential functions as they are very slow. If you want a path, then use the mp_grid functions instead. they are faster and will give the same, if not better, results.
My problem with mp_grid is that every time I try and use it, it yields unexpected results (such as not following within a certain quadrant)
I also just learned that when using mp_potential_path as a check, it basically the same as just calling it.
 
Top