J
JCrockford1
Guest
I need my turret to shoot the leading enemy in my Tower Defence game, however, when the bullet collides with the enemy all the enemies on the screen is destroyed. Here is the code in my obj_Tower step event:
///Rotate with Enemy and shoot
if(instance_exists(obj_enemyPar))
{
enemyid = 0;
for(var i = 0; i < instance_number(obj_enemyPar) i++)
{
var enemy = instance_find(obj_enemyPar,i);
var enemyDistance = point_distance(x,y,enemy.x,enemy.y)
if(enemyDistance <= range)
{
if(enemyid==0) enemyid = enemy
var pos = enemy.path_position
if (pos > enemyid.path_position) enemyid = enemy
}
if (enemyid != 0)
{
dirOfE = point_direction(x,y,enemyid.x,enemyid.y)
image_angle = dirOfE
if (canShoot)
{
instance_create(x,y,obj_bullet)
canShoot = false
alarm[1] = reloadSpd
}
}
}
}
I cannot find the problem but hopefully one of you will.
///Rotate with Enemy and shoot
if(instance_exists(obj_enemyPar))
{
enemyid = 0;
for(var i = 0; i < instance_number(obj_enemyPar) i++)
{
var enemy = instance_find(obj_enemyPar,i);
var enemyDistance = point_distance(x,y,enemy.x,enemy.y)
if(enemyDistance <= range)
{
if(enemyid==0) enemyid = enemy
var pos = enemy.path_position
if (pos > enemyid.path_position) enemyid = enemy
}
if (enemyid != 0)
{
dirOfE = point_direction(x,y,enemyid.x,enemyid.y)
image_angle = dirOfE
if (canShoot)
{
instance_create(x,y,obj_bullet)
canShoot = false
alarm[1] = reloadSpd
}
}
}
}
I cannot find the problem but hopefully one of you will.