0

我一直在尝试编写一些 GML 脚本,但在某些时候完全卡住了。我希望敌人攻击我的主角,但不要重叠。所以,我会说。

//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
}

这是一张描述我想要得到的图像(请注意,敌人知道他们应该攻击,即使他们没有与主角直接接触,只是因为除此之外的敌人正在攻击)

我想得到什么...

4

1 回答 1

0

由于实例放置功能,我终于能够做到这一点。

我会发布代码以防有人需要类似的东西

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;
}

和结果 结果

于 2015-01-17T01:03:12.417 回答