0

I've been trying to do some GML scripting but got totally stuck at some point. I want enemies to attack my main character but without overlapping. So, I would say.

//enemy is moving left-to-right...
if place_meeting(x+1, y, enemy){ //if there's a collision with another enemy
   if (other enemy).is_attacking{ // ???
   // checks if the colliding enemy is attacking, if true, it should attack as well...
   is_attacking=true;
   }else{
   //walks
}

This is an image that describes what I'm trying to get (note that enemies know they should be attacking even though they're not in direct contact with the main character, just because an enemy besides is attacking)

What I'm trying to get...

The Guy with The Hat
  • 10,836
  • 8
  • 57
  • 75
Fran Cano
  • 667
  • 1
  • 9
  • 18

1 Answers1

0

I was finally able to do it thanks to the instance place function.

I will post the code in case someone need somethin similar

if place_meeting(x+5, y, malo){ //malo means enemy on spanish, i use to write multilingual code, lol :P
          var inst;
          inst=instance_place(x+15,y,malo); //x varies on sprite size. it basically returns the unique id of the object that's 15 pixels on the right of self (malo)
    with (inst){
        if (is_attacking){
        other.is_attacking=true; //if collided enemy is attacking, then this(other) enemy should attack too. search more about the width statement if you don't catch this part
        }else{
        other.is_attacking=false;
        hspeed=1;
        }
    }
}else if place_meeting(x+3, y, character){
is_attacking=true;
}else{
is_attacking=false;
hspeed=1;
}

and the result the result

Fran Cano
  • 667
  • 1
  • 9
  • 18
  • If this answer satisfactorily solves your problem, you should accept it by clicking the checkmark next to it. The same applies to any other question you may ask in the future. If you want more information, you can look at this Meta post: [How does accepting an answer work?](http://meta.stackexchange.com/q/5234/238586). – The Guy with The Hat Jan 21 '15 at 19:17