construct.net/en/forum/construct-3/how-do-i-8/tactically-intelligent-ai-173259
I looked into past posts and did some digging and discovered this system made in Gamemaker, https://youtu.be/XuhkKmNyYTY
It does everything I need it to do, but I can't figure out how it finds cover. I used to use GM a long time ago but I can't wrap my head around this function.
This is the code that finds cover
function scr_find_cover(argument0, argument1, argument2) {
/*
If there is line of site between the target enemy and yourself, then
move behind the nearest wall.
*/
can_shoot=0 //don't shoot while in this state
if !collision_line(x+lengthdir_x(argument0.sprite_width,point_direction(argument0.x,argument0.y,x,y)),y+lengthdir_y(argument0.sprite_width,point_direction(argument0.x,argument0.y,x,y)),argument1.x,argument1.y,argument0,1,1)
//if line of sight....
{
//pathfind to a point behind the nearest wall relative to the enemy
mp_potential_step(argument0.x+lengthdir_x(argument0.sprite_width,point_direction(argument1.x,argument1.y,argument0.x,argument0.y)),argument0.y+lengthdir_y(argument0.sprite_width,point_direction(argument1.x,argument1.y,argument0.x,argument0.y)),argument2*2,0)
}
else
{
//if there is no line of sight (you are in cover), then decrease your fear level.
fear-=1
}
}
From my understanding, the fear level is a instance variable that makes enemies take cover when its high.
"Argument0" is the nearest wall, "Argument1" is the target or the attacker and "Argument2" is the enemies speed.
If you could translate this then that would be awesome, and if you need anymore details please ask me. Thank you