Stonesword games
Member
Hello I am making a top down spaceship shooter and I am currently using this script when the bullet is activated
//when the player gets close it shoots the bullet (enemy step event)
if (distance_to_object(obj_player)) <= 1000 && (cooldown < 1) {
instance_create_layer(x,y,"bullets",obj_bullet1)
cooldown = 10;
//Lazer sound & pitch
audio_play_sound(snd_lazer3,10,false)
audio_sound_pitch(snd_lazer3,random_range(0.8,1.2));
}
cooldown = cooldown - 1.0
//script
{
var origin,target,pspeed,dir,alpha,phi,beta;
origin = argument0;
target = argument1;
pspeed = argument2;
dir = point_direction(origin.x,origin.y,target.x,target.y);
alpha = target.speed / pspeed;
phi = degtorad(target.direction - dir);
beta = alpha * sin(phi);
if (abs(beta) >= 1) {
return (-1);
}
dir += radtodeg(arcsin(beta));
return dir;
}
//and I have this is the bullets creat event
direction = script_execute(scr_targeting,obj_enemy,obj_player,17)
my problem is that when there are multiple enemies, only one is shooting the player accurately, the others look like they are shooting based on where the accurate enemy is positioned .
asking for a friend
//when the player gets close it shoots the bullet (enemy step event)
if (distance_to_object(obj_player)) <= 1000 && (cooldown < 1) {
instance_create_layer(x,y,"bullets",obj_bullet1)
cooldown = 10;
//Lazer sound & pitch
audio_play_sound(snd_lazer3,10,false)
audio_sound_pitch(snd_lazer3,random_range(0.8,1.2));
}
cooldown = cooldown - 1.0
//script
{
var origin,target,pspeed,dir,alpha,phi,beta;
origin = argument0;
target = argument1;
pspeed = argument2;
dir = point_direction(origin.x,origin.y,target.x,target.y);
alpha = target.speed / pspeed;
phi = degtorad(target.direction - dir);
beta = alpha * sin(phi);
if (abs(beta) >= 1) {
return (-1);
}
dir += radtodeg(arcsin(beta));
return dir;
}
//and I have this is the bullets creat event
direction = script_execute(scr_targeting,obj_enemy,obj_player,17)
my problem is that when there are multiple enemies, only one is shooting the player accurately, the others look like they are shooting based on where the accurate enemy is positioned .
asking for a friend
Last edited: