Mr Awesome
Member
I am trying to make my my standard missiles turn into homing missiles to finish off a boss (obj_monkeytron)
I am using this code in the create and step event, but the missiles fly past him off the screen. Originally the code was for when there were multiple instances of the same object on screen and it worked fine. I have tried to modify it to get the effect I want but no luck. I think I need to take it out of the step event.
Any help and code refining much appreciated.
I am using this code in the create and step event, but the missiles fly past him off the screen. Originally the code was for when there were multiple instances of the same object on screen and it worked fine. I have tried to modify it to get the effect I want but no luck. I think I need to take it out of the step event.
GML:
Create:
if instance_exists(obj_cow2_bullet_spawner) sprite_index=spr_bul_poo#for other levels
if room !=room_COW2 and global.homing==0{#for other levels
direction = point_direction(x, y, mouse_x, mouse_y);#for other levels
image_angle = direction;#for other levels
speed = 16;#for other levels
}else{#for other levels
direction=choose(180,190,210,200,160,150,)#for other levels
image_angle=direction#for other levels
speed=8#for other levels
if global.homing==0{//This turns miisiles into homing, added again here to stop poo audio being played
if !audio_play_sound(sou_bul_poo,1,0){
audio_play_sound(sou_bul_poo,1,0)
}
}
}
Code:
Step
//Homing missle vars
var dir, accel, ex, ey, enemy, max_speed;
enemy=obj_monkeytron
accel=.5
max_speed=16//Missles are now hoimng missles
if global.homing==1 and instance_exists(enemy){
//First three lines show what enemy is closest
//ex=instance_nearest(x,y,enemy).x;
//ey=instance_nearest(x,y,enemy).y;
dir=point_direction(x,y,enemy.x,enemy.y);//Points at the lcosest enemy nearby
motion_add(dir,accel);//Movement
if speed>=max_speed{speed=max_speed}
image_angle=direction;
if distance_to_object(enemy)<15{
move_towards_point(enemy.x,enemy.y,speed);
}
}