D
dannyisfree
Guest
Hey,
I've been trying to create a Hotline Miami clone as a learning experience, but I keep running into the same problem with the AI. The enemies keep going off the level and through the walls after the player gets near the edges of the level.
obj_ grid code:
obj_enemy add path code:
obj_enemy sight code:
obj_enemy follow path code:
The enemies create a straight line with the player and checks if there's any walls between them, if there isn't a wall, the enemy will face their direction in order to shoot at the player. Once the player is out of the line of sight after being seen, the enemy will go into chase mode where it uses path finding to get to the player. Once it sees the player again, it stops in its tracks to shoot at the player.
Any help is appreciated, thanks.
I've been trying to create a Hotline Miami clone as a learning experience, but I keep running into the same problem with the AI. The enemies keep going off the level and through the walls after the player gets near the edges of the level.
obj_ grid code:
Code:
//Create the grid
var cell_width = 32
var cell_height = 32
var hcells = room_width div cell_width
var vcells = room_height div cell_height
global.grid = mp_grid_create(0,0,hcells,vcells,cell_width,cell_height)
//add the walls
mp_grid_add_instances(global.grid,obj_wall,true)
Code:
path = path_add();
Code:
spot_dir = point_direction(x,y,obj_player.x,obj_player.y) //view line check direction
target=collision_line(x,y,x+lengthdir_x(range,spot_dir),y+lengthdir_y(range,spot_dir),obj_player,true,true) //checks for player
if instance_exists(target){
if !collision_line(x,y,target.x,target.y,obj_wall,true,true){ //checks if theres a wall
chase = true
seen=true; //if theres no wall, the player is seen
}else{
seen=false; //else, the player is not seen
}
}
Code:
///AI
var plr_x = (obj_player.x div 32)*32+16
var plr_y = (obj_player.y div 32)*32+16
if !seen && chase {
mp_grid_path(global.grid,path,x,y,plr_x,plr_y,1)
path_start(path,spd,path_action_stop,false)
}
Any help is appreciated, thanks.