Roastedzerg
Member
Edit 2: Heres the work around solution i used to check for nearby walls to decide if the enemy should aim ahead of his target or directly at them. Its not perfect but it worked well for my game.
Hey guys, I'm using a script that makes the shooting enemies in our game aim ahead of their targets and so far its working relatively well. However they have no way to know if there is a wall in the direction they're aiming or not so they end up trying to shoot ahead of the player only to shoot the wall beside themselves. How can i adjust the following script to incorporate walls so they will stop adjusting if they aim towards one?
Edit 1: the variable _t is determining the time it takes based on the distance from enemy to target multiplied by the projectile speed. Also i know i need something like collision_line in there to find a wall that could be intersecting with our aiming line, but dont know where i should put it and how i should modify the calculations to incorporate this collision detection.
I'm not looking for anyone to just hand out the answer, though i would appreciate it if they do, but even a simple suggestion would be enough to help. Thank you
Screencaps for more details:
In the above screenshot the target is the white rectangle and the enemy shooting is the green square to the left. The red line between them represents the aiming which is straight forward as the target is not moving. The green circle is the projectile.
In the next screenshot the target (white rectangle) is moving downwards and the enemy (now a dark blue to represent hes in the aiming state) is trying to compensate by aiming down to where the target will be compared to both of their x and y speeds and coordinates. What im trying to do is make the enemy who is aiming stop compensating when he has aimed a few pixels away from the wall. Right now as you can see he aims as if there were no wall between himself and his target.
GML:
var _p=1/projectile_speed;
var _x=my_target.x;
var _y=my_target.y-my_target.hurtbox_height;
var _u=my_target.x_speed;
var _v=my_target.y_speed;
//Determine the distance and time it takes for projectile to reach target, each iteration increases accuracy
var _d=point_distance(x,y-height,_x,_y);
var _t=_d*_p;
var _d=point_distance(x,y-height,_x+_u*_t,_y+_v*_t);
var _t=_d*_p;
var _d=point_distance(x,y-height,_x+_u*_t,_y+_v*_t);
var _t=_d*_p;
var box_buff=200;
if(!collision_rectangle(bbox_left-box_buff,bbox_top-box_buff,bbox_right+box_buff,bbox_bottom+box_buff,obj_block_bullet,0,1))
{
aim_x=_u*_t;
aim_y=_v*_t;
}
else
{
aim_x=0;
aim_y=0;
}
GML:
var _p=1/projectile_speed;
var _x=my_target.x;
var _y=my_target.y-my_target.hurtbox_height;
var _u=my_target.x_speed;
var _v=my_target.y_speed;
//Determine the distance and time it takes for projectile to reach target, each iteration increases accuracy
var _d=point_distance(x,y-height,_x,_y);
var _t=_d*_p
var _d=point_distance(x,y-height,_x+_u*_t,_y+_v*_t);
var _t=_d*_p
var _d=point_distance(x,y-height,_x+_u*_t,_y+_v*_t);
var _t=_d*_p
aim_x=_u*_t;
aim_y=_v*_t;
aim_dir=point_direction(x,y-height,my_target.x+aim_x,my_target.y-my_target.hurtbox_height+aim_y);
Edit 1: the variable _t is determining the time it takes based on the distance from enemy to target multiplied by the projectile speed. Also i know i need something like collision_line in there to find a wall that could be intersecting with our aiming line, but dont know where i should put it and how i should modify the calculations to incorporate this collision detection.
I'm not looking for anyone to just hand out the answer, though i would appreciate it if they do, but even a simple suggestion would be enough to help. Thank you
Screencaps for more details:
In the above screenshot the target is the white rectangle and the enemy shooting is the green square to the left. The red line between them represents the aiming which is straight forward as the target is not moving. The green circle is the projectile.
In the next screenshot the target (white rectangle) is moving downwards and the enemy (now a dark blue to represent hes in the aiming state) is trying to compensate by aiming down to where the target will be compared to both of their x and y speeds and coordinates. What im trying to do is make the enemy who is aiming stop compensating when he has aimed a few pixels away from the wall. Right now as you can see he aims as if there were no wall between himself and his target.
Last edited: