The player has an ability to summon a drone and help him, what the drone does is shoot to enemies and follow the player.
Everything works perfect but it has something that i don't like...
If the drone see's an enemy it stars shooting, when killed it stop, but it even shoot to enemies that are behind a wall. i want to make my drone dont shoot if an obj_solid is blocking the way, here is my code
Create event:
canshot = 1;
aggroRange = 300;
Step event:
if (instance_number(obj_enemy) > 0){
var ex = instance_nearest(x, y, obj_enemy).x; //Localize nearest enemy
var ey = instance_nearest(x, y, obj_enemy).y;
var dis = point_distance(x,y,ex,ey);
if (dis <= aggroRange && canshot == 1){ //If enemy is in range and able to shot
with (instance_create(x, y, obj_summonbullet)){
direction = point_direction(x, y, ex, ey);
}
canshot = 0;
alarm[3] = 0.25*60; //When the alarm reaches 0 it does the drone is able to shoot again
}
}
Thanks C:
Everything works perfect but it has something that i don't like...
If the drone see's an enemy it stars shooting, when killed it stop, but it even shoot to enemies that are behind a wall. i want to make my drone dont shoot if an obj_solid is blocking the way, here is my code
Create event:
canshot = 1;
aggroRange = 300;
Step event:
if (instance_number(obj_enemy) > 0){
var ex = instance_nearest(x, y, obj_enemy).x; //Localize nearest enemy
var ey = instance_nearest(x, y, obj_enemy).y;
var dis = point_distance(x,y,ex,ey);
if (dis <= aggroRange && canshot == 1){ //If enemy is in range and able to shot
with (instance_create(x, y, obj_summonbullet)){
direction = point_direction(x, y, ex, ey);
}
canshot = 0;
alarm[3] = 0.25*60; //When the alarm reaches 0 it does the drone is able to shoot again
}
}
Thanks C:
Attachments
-
28.7 KB Views: 3