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

GameMaker Enemy AI Help

C

CrackedGamer§

Guest
I need help with the enemy AI in a top-down game I am working on. I want them to collide with obj_solid and walk around it on collision.

All code I have at the moment is:

Create:
Code:
enemyspd=5
spotted = false
Step:
Code:
//Pause After Attack
if(place_meeting(x, y, obj_player)) {
    enemyspd = 0;
    alarm[0] = 30;
}
else if(alarm[0] == 0) {
    enemyspd = 5;
}

//Attack Player
if(spotted=true){
script_execute(scr_attack_player());
}

//Spotting The Player
if(place_meeting(x, y, obj_enemy_detection_range)){
        spotted = true;
        global.inbattle = true;
} else{
    spotted = false;
    global.inbattle = false;
}
Alarm0:
Code:
enemyspd = 5;
Collision (obj_sword):
Code:
global.inbattle = false
instance_destroy();
All of this is in the object called obj_enemy_wolf but I want it to be useable with any enemy I create with the same movement (except speed and other minor changes that I can manage myself). Thank you Bayesian for showing me the code blocks.
 
Last edited by a moderator:
B

Bayesian

Guest
Also, I just want to say that this is my first post and thus I can't just replace the code with pastebin links.
Just for future reference we don't usually like paste bins anyway but we do appreciate code blocks like this
Code:
code
You can make them by clicking the page button to the left of the save icon in the post editor and just paste your code into the popup window
 
C

CrackedGamer§

Guest
Just for future reference we don't usually like paste bins anyway but we do appreciate code blocks like this
Code:
code
You can make them by clicking the page button to the left of the save icon in the post editor and just paste your code into the popup window
Thank you!
 
F

Floki

Guest
W
I need help with the enemy AI in a top-down game I am working on. I want them to collide with obj_solid and walk around it on collision.

All code I have at the moment is:

Create:
Code:
enemyspd=5
spotted = false
Step:
Code:
//Pause After Attack
if(place_meeting(x, y, obj_player)) {
    enemyspd = 0;
    alarm[0] = 30;
}
else if(alarm[0] == 0) {
    enemyspd = 5;
}

//Attack Player
if(spotted=true){
script_execute(scr_attack_player());
}

//Spotting The Player
if(place_meeting(x, y, obj_enemy_detection_range)){
        spotted = true;
        global.inbattle = true;
} else{
    spotted = false;
    global.inbattle = false;
}
Alarm0:
Code:
enemyspd = 5;
Collision (obj_sword):
Code:
global.inbattle = false
instance_destroy();
All of this is in the object called obj_enemy_wolf but I want it to be useable with any enemy I create with the same movement (except speed and other minor changes that I can manage myself). Thank you Bayesian for showing me the code blocks.
Would mp_grid and mp_grid_path work for your application?
I've played around with it and adding a new path for an object to follow when a collision is detected, then destroying that path and continuing with a walking cycle was pretty simple.
 
Top