I have an enemy that moves or shoots based on distance to the player.
After looking at lots of different tutorials I've just become confused and am not really sure how I should be using this alarm because the if just seems to ignore it.
I also think it could be to do with how I'm using my boolean.
(The two if's at the bottom is where my alarm is)
enemy step event:
Alarm [0] event:
After looking at lots of different tutorials I've just become confused and am not really sure how I should be using this alarm because the if just seems to ignore it.
I also think it could be to do with how I'm using my boolean.
(The two if's at the bottom is where my alarm is)
enemy step event:
GML:
var PX = x + lengthdir_x(-16, image_angle);
var PY = y + lengthdir_y(-10, image_angle);
var player = obj_ship;
// Look at and follow the player until certain distance then shoot
if(instance_exists(obj_ship)){
image_angle = point_direction(x, y, obj_ship.x, obj_ship.y);
var sx, sy;
sx = instance_nearest(x, y, player).x;
sy = instance_nearest(x, y, player).y;
if(point_distance(x, y, sx, sy) > 200){
// Move towards the player
motion_add(image_angle, 0.03);
part_type_color2(global.ptBasic, c_red, c_orange);
part_particles_create(global.partSystem, PX, PY, global.ptBasic, 1);
}
if canshoot
{
if(point_distance(x, y, sx, sy) <= 180){
canshoot = false;
alarm[0] = 90*room_speed;
var inst = instance_create_layer(x,y, "Instances", obj_bullet_enemy);
inst.direction = image_angle;
//audio_play_sound(snd_shoot, 1, false)
}
}
}
move_wrap(true,true,sprite_width/2);
GML:
canshoot = bool(true);
Last edited: