Legacy GM Detect only ahead

T

TinShigi

Guest
Hi again! I've made an enemy that will start shooting if the player gets in a certain range of visibility and won't stop until they leave, but unfortunately it seems to include behind itself as part of that radius too and I need to get it to stop that. Does anyone have any suggestions?

Code:
//Ataque
var radius = 100;
var sight = !collision_line(x, y, x+radius*dir, y, par_solid, false, true); 
var InsideRadius = distance_to_point(obj_player.x,obj_player.y) < radius; 

if(sight & InsideRadius){ 
if canshoot = 0 {
    instance_create (x+6*dir,y,obj_sfireball)
    canshoot = 25;
}
}

if canshoot >0 {canshoot --;}
"dir" is the variable im using for every entity I have to keep track of which way they should be facing.
 
A

anomalous

Guest
Maybe something like this:
You mention you keep track of dir for facing of everyone.
So the enemy has a dir? If so, do a direction check in addition to sight radius.
Check if the angle to the player is within the angle_offset amount (+- 30 degrees in the below example).

var angle_offset = 30;
var player_dir = point_direction (x,y,obj_player.x, obj_player.y);
var oklos = false;

if player_dir < (dir + angle_offset) && player_dir > (dir-angle_offset)
{
oklos = true;
}
if (sight && InsideRadius && oklos)
 
Top