GMS 2 Troubles with Enemy AI movement

Discussion in 'Programming' started by Mr Tim the Wizard, Feb 11, 2019.

  1. Mr Tim the Wizard

    Mr Tim the Wizard Member

    Joined:
    Mar 2, 2018
    Posts:
    12
    I am attempting to create a simple top-down shooter game. I have attempted to mess around with an AI system and am currently using the built-in gamemaker AI system. I have, however, run into problems with things such as knockback or have the AI roam.
    Any suggestions for how to fix these issues or to completely change the AI system would be greatly appreciated.

    This is my code:

    ///Game start grid
    globalvar grid;
    grid = mp_grid_create(0, 0, room_width div 32, room_height div 32, 32, 32);
    mp_grid_add_instances(grid, oWall, true);

    if ev_game_start {
    timer3 -= 1

    if timer3 >= 0 {
    mp_grid_add_instances(grid, oEnemy, false);
    }
    }

    ///Movement grid
    globalvar grid;
    grid = mp_grid_create(0, 0, room_width div 32, room_height div 32, 32, 32);
    mp_grid_add_instances(grid, oWall, true);

    if ev_game_start {
    timer3 -= 1

    if timer3 >= 0 {
    mp_grid_add_instances(grid, oEnemy, false);
    }
    }

    ///Path
    with(oEnemy) {
    path = path_add();
    if mp_grid_path(grid, path, x, y, oPlayer.x, oPlayer.y, 1)
    {
    path_start(path, yp, 3, 0);
    }
    }



    ///Stop the enemies movement
    yp = 1.5

    if distance_to_object(oPlayer) <= 128 {
    yp = 0.00000000000000000000000000000000001
    sprite_index = sEnemy
    }

    if distance_to_object(oPlayer) >= 129 {
    sprite_index = sEnemyR
    }
     
  2. Tommah

    Tommah Member

    Joined:
    Jun 21, 2016
    Posts:
    54
    what exactly are the issues? is knockback not doing anything? is enemy not roaming at all?

    Instead of changing speed if player is too far away you could just end the path...

    Code:
    ///Path
    with(oEnemy) {
    path = path_add();
    if (mp_grid_path(grid, path, x, y, oPlayer.x, oPlayer.y, 1) && distance_to_object(oPlayer<=128))
    {
       path_start(path, yp, 3, 0);
       sprite_index=sEnemy;
    }
    else{
       path_end();
       sprite_index=sEnemyR;
    }
    }
    
     
  3. Mr Tim the Wizard

    Mr Tim the Wizard Member

    Joined:
    Mar 2, 2018
    Posts:
    12
    My issue is that I don't know how to go about making an AI system, so I was going to the forums to ask about possible ways I could add enemy knockback and roaming. I did more research and found out how to, however. Thanks!
     

Share This Page

  1. This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
    By continuing to use this site, you are consenting to our use of cookies.
    Dismiss Notice