X
x365
Guest
I'm at an absolute loss. Long story short, I have an obj_Player (naturally), obj_Enemy and obj_Friendly. I wan't obj_Friendly to flee when obj_Enemy is within var=attentionRange.
They both wander randomly in their normal state, however obj_Enemy has a follow state, to chase down the player. Regardless of obj_Enemys state, I want the obj_Friendly to flee when obj_Enemy is close enough.
I should mention I am relatively new to GM:S, but have been able to figure most out so far up until this point.
I want to check if the nearest obj_Enemy is within attentionRange with instance_nearest, but my attempts through the past 8 hours have all been failures. I have googled extensively and found basically every thread imaginable on how instance_nearest works. I have resorted to a simpler example to get the code to work for now, yet this fails me as well. I can't see that I have a syntax issue, but I sure hope that is it.
My simpler test is as follow:
I have tried substituting obj_Enemy with a parent object called obj_Parent_Enemy to no avail.
All my obj_Enemy's are spawned with a spawner (thus not placed in the room editor!), and I can only expect that to have something to say (basic instance_create of obj_Enemy at a random place in the room basically).
So in short; what am I doing wrong? How can I not set the eTarget variable to be the closest enemy with instance_nearest?
Thanks!
They both wander randomly in their normal state, however obj_Enemy has a follow state, to chase down the player. Regardless of obj_Enemys state, I want the obj_Friendly to flee when obj_Enemy is close enough.
I should mention I am relatively new to GM:S, but have been able to figure most out so far up until this point.
I want to check if the nearest obj_Enemy is within attentionRange with instance_nearest, but my attempts through the past 8 hours have all been failures. I have googled extensively and found basically every thread imaginable on how instance_nearest works. I have resorted to a simpler example to get the code to work for now, yet this fails me as well. I can't see that I have a syntax issue, but I sure hope that is it.
My simpler test is as follow:
Code:
var eTarget=instance_nearest(x,y,obj_Enemy)
if (distance_to_object(eTarget) < 100) {
draw_set_colour(c_maroon);
draw_text(view_xview[0]+15, view_yview[0]+80, "PROXIMITY ALERT")
}
All my obj_Enemy's are spawned with a spawner (thus not placed in the room editor!), and I can only expect that to have something to say (basic instance_create of obj_Enemy at a random place in the room basically).
So in short; what am I doing wrong? How can I not set the eTarget variable to be the closest enemy with instance_nearest?
Thanks!