• 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 Another Enemy Movement AI w/ mp_potential_step

K

KiD_Rager

Guest
Yo friendos!

Like the title suggests, I'm dealing with some enemy movement issues. Before I go into it, I've watched countless YouTube videos, read and tested several threads on here and Reddit, and experimented with the mp_grid stuff as well. That being said:

My issue is that enemies do a great job following the player w/ mp_potential_step; however, get clustered when a wall comes between the player and enemy. I have a push variable that makes sure the enemies don't overly each other, but I suspect that's what is causing the enemy to get stuck on a wall.

https://i.gyazo.com/70617182fdd1bf89fc41c9f1c50f601e.mp4

In enemy's STEP:

Code:
if (hp < 1) {
    scr_zombie_dead();
}

//Flip Rotation
if instance_exists(obj_player) {
    if (x > obj_player.x) { image_xscale = 1; }
        else { image_xscale = -1; }
}

//Check speed in certain situations
    
if (global.move == false) {
    chase = false;
    image_speed = 0;
    }
else {
    if (sprite_index = spr_zombie) && (room == rm_frenzy) {
    chase = true;
    }
}

//Check if attacking player
    
if (collision_circle(x,y,10,obj_player,false,true)) {
        z_speed = 0;
        if (sprite_index != spr_zombie_attack_wall) {
            health -= 1;
        }
        sprite_index = spr_zombie_attack_wall;
        alarm[1] = room_speed * 0.25;
        chase = false;
    }

//Check if zombie can chase
    
if (chase == true) {
    scr_zombie_move();
}

else {
    z_speed = 0;
}

In scr_zombie_move():

GML:
z_speed = 0 + global.z_spd_mult;
mp_potential_step(obj_player.x,obj_player.y,z_speed,false);

In enemy COLLISION WITH ITSELF:

Code:
///Push other zombies away
var push = 1;
x -= lengthdir_x(push,point_direction(x,y,other.x,other.y));
y-= lengthdir_y(push,point_direction(x,y,other.x,other.y));

Note: Collision check with wall is not the reason why, as if my player moves closer to an opening in the wall, the enemies re-adjust themselves to stop being clustered and seemingly "slide" down the wall, managing to go around and get to the player. That works.

The z_speed stuff doesn't affect the mp_potential_step as it only adjusts the speed of the enemy when a new round happens.

When I removed said code and attempted the mp_grid concept, the enemy would indeed go to where my player was, but if the player ever left that position, the enemy would continue to where the player used to be and stop. So I tried modifying it with STEP instead of CREATE, but it would lag the game entirely. Then I used alarms as a trick to check every X seconds whether to continue the grid or do mp_potential_step instead (if a player was within a certain distance away). Unfortunately, this process did not work either.

None of the solutions I've researched seem to create a fluid enemy path-finding system. Was hoping for different thoughts as to what I can do. :)

Thanks!
 
Top