Homing bullets help

A

AVUOX

Guest
How do I make my homing bullets spread to different enemies if the enemy is one instance? Like I have enemy A created multiple times but the homing bullets will only home in on the "first" created rather than the newly created ones.
 

Alexx

Member
For a basic system you can add the id's of a target to a ds_list, then check if one is already being targeted.

If all are being targeted, you would need to decide what to do in that case.
 
M

Maloso

Guest
Unfortunately your question is too open-ended as you haven't specified what you're actually wanting the homing missiles to do.
Do you want them to lock-on to enemies randomly? Lock-on to the nearest? Lock-on to a different enemy per missile? etc.
If you fire two missiles that lock-on to the same enemy, and the first missile kills the enemy, what do you want the second missile to then do?
 
I assume you are currently just using some code like this:
Code:
target_x = oEnemy.x;
target_y = oEnemy.y;
//do homing bullet stuff now
This will only find the original object's position, not any of its other instances. You should use instance_nearest instead of specifying a specific object_id like "oEnemy".
Code:
var inst = instance_nearest(xx, y, object_index);  //try to find nearest instance
if (inst != noone)  //must check to make sure an instance exists
   {
        target_x = inst.x;
        target_y = inst.y;
       //do homing bullet stuff
   }
 
Last edited:
A

AVUOX

Guest
Holy crap thank u a whole lot shadowspear1, that code u provided above was exactly what i was looking for!
 
Top