GML Hello again, can you help me to create a script that works so that an object (enemy) has several targets depending on its proximity?

Dany24

Member
hello, I am creating a tower defence type platformer and I have had problems to make a good enemy that enemy has to destroy different objects(walls, doors, player) before reaching the "nexus"(main objective)the problem I have is to make the enemy move and stop near the target and destroy it and then continue with the next one I appreciate your help, it is the last thing I need to fix to finish the development.
GML:
///event create
objective[0] = obj_nexus;
objective[1] = obj_Bdoor;
objective[2] = obj_Pplayer;


var tar = argument0; // Always the first set target
var bar = instance_nearest(x,y,obj_nexus)
var list = ds_priority_create(); //Create a priority list
if distance_to_object(bar) < 16 {
tar = bar;
}else {

for (var i = 0; i < array_length_1d(objective); i++) { //Loops through all objectives
ds_priority_add(list,objective[i].id,distance_to_point(objective[i].x,objective[i].y)) //Adds the objects and distances | Compares them
}
tar = ds_priority_find_min(list) //Returns the closest objective
}

return tar;
This is the search code, but what I don't know is how to apply it to a horizontal platform movement. I have used other types of object movements but never the platform movement with gravity and AI jumps.
 
Last edited:

woods

Member
without seeing your code, people here are going to be shooting into the void for possible fixes and helping ;o)

but i would use a state machine for this.

enemy has a main goal (the nexus) //main target
add in distance checks for the things that you want the enemy to target(doors, walls, player, etc) //temp target
if there is no temp target within range, move on to main target else attack temp target
 
Top