• 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 [SOLVED] help with efficiency to keep frame rate from going down.

So I have a Pac-Man like game and it's functional but the frame rate goes down when too many enemies are seeking out the player. there are only 10 enemies on the board at one time plus the Minotaur who is always chasing down the player. I think maybe grid pathfinding might help but I would have to learn how to use them.

I do know that when I tried to put (if player exists) instead of (collision circle) that the frame rate almost crashed the game. I also think game states could help but not sure where or how to implement them.

Enemy step:
Code:
var myPath = path_add();
if (collision_circle(x,y,576,objPlayer,false,true)) {
    mp_potential_path(myPath,objPlayer.x,objPlayer.y,4,4,false);
    path_start(myPath,4,path_action_stop,true);
}
 
my player is using automatic/ rectangle with no animation. i do have a floating sword sprite that's rotated by mouse position, which is also automatic/ rectangle. the precise collision mask that i do use is on the slash sprite, with no animation.
33d15bd1-d828-4178-8a1e-52733ae08c36.png 4bdb431d-2312-414d-8042-e1c4bfd810a7.png 5ca612c7-cedc-408c-8a1b-08ae0c2e4dcc.png
player draw instance:
Code:
draw_self();
var dir = point_direction(x,y,mouse_x,mouse_y);
draw_sprite_ext(sSword,0,x,y,1,1,dir,image_blend,image_alpha);
 

Geners

Member
I agree with Curato.

Use distance_to_object and then check if that distance is less than the radius of the detection circle you want to use. This will have a similar effect as having a collision circle.
 
A

Annoyed Grunt

Guest
You should begin by not creating a new path every step, that can't be good for your framerate or memory. Then, if you still have issues, you can make path recalculation rarer. I would begin by only recalculating the path every 5 steps or so, and only doing so if the player has moved a decent amount.

I agree with Curato.

Use distance_to_object and then check if that distance is less than the radius of the detection circle you want to use. This will have a similar effect as having a collision circle.
I don't think collision_circle is the culprit, even if it's ten times slower than a simple distance check (which is unlikely, it's probably just a rectangle-to-circle intersection test) it's still only called 11 times per step.
 
if (distance_to_object(objPlayer) < 576) acted pretty much the same with the same frame rate loss with more enemies closing in. but i get what you are saying, this is checking for less information than collision circle.
 
You should begin by not creating a new path every step, that can't be good for your framerate or memory. Then, if you still have issues, you can make path recalculation rarer. I would begin by only recalculating the path every 5 steps or so, and only doing so if the player has moved a decent amount.



I don't think collision_circle is the culprit, even if it's ten times slower than a simple distance check (which is unlikely, it's probably just a rectangle-to-circle intersection test) it's still only called 11 times per step.
yea that's what i was thinking when i was thinking about putting in states. where the state is collision checking and then switches to pursue. but i'm not sure how i'd have it check every five steps. maybe with an alarm or count down
 

JackTurbo

Member
Creating a new path every step is overkill and deffo a big resource hog. Do it in an alarm and call that at random intervals. I have my AI tick around every third of a second +/- 10 frames.

Randomising it a little helps spread the load out across multiple steps so you don't get certain steps where all enemies pathfind
 
so i dont really know how to do alarms correctly but someone helped me with this code to fix another problem with my alarms. so far it's fixing the frame rate drop but i cant use it everywhere like with the minotaur, where i have him go faster when he is closer and with the delay he pauses between cruising and chase speeds while cycling through the .2*room_speed. lowering that number helps with the delay but i dont quite remember how to put my count down by frame instead of room_speed for this equation. i'm sure it'll fix it if i set it to about 5 frames count down though. otherwise, it's running way smoother.

Enemy create:
pathcheck = .2*room_speed;

enemy step event:
Code:
if (distance_to_object(objPlayer) < 576) {
    if (pathcheck > 0){
        pathcheck -= 1;
    }
    else
    {
        mp_potential_path(myPath,objPlayer.x,objPlayer.y,4,4,false);
        path_start(myPath,4,path_action_stop,true);
        pathcheck = .2*room_speed;
    }
}
 
Top