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

[SOLVED] Make turret dont shoot if obj_solid is blocking

Megax60

Member
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:
 

Attachments

YellowAfterlife

ᴏɴʟɪɴᴇ ᴍᴜʟᴛɪᴘʟᴀʏᴇʀ
Forum Staff
Moderator
You can use collision_line to ensure that there are no walls between the turret and the target, that is,
Code:
if (dis <= aggroRange && canshot == 1){ //If enemy is in range and able to shot
=>
Code:
if (dis <= aggroRange && canshot == 1
&& collision_line(x, y, ex, ey, obj_solid, true, false) == noone){ //If enemy is in range and able to shot
 

Megax60

Member
You can use collision_line to ensure that there are no walls between the turret and the target, that is,
Code:
if (dis <= aggroRange && canshot == 1){ //If enemy is in range and able to shot
=>
Code:
if (dis <= aggroRange && canshot == 1
&& collision_line(x, y, ex, ey, obj_solid, true, false) == noone){ //If enemy is in range and able to shot

it works, thanks!
 
Top