我一直试图做一些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
}
这张图片描述了我想要得到的东西(注意敌人知道他们应该攻击,即使他们并没有与主角直接接触,只是因为其他敌人正在攻击)
答案 0 :(得分:0)
由于instance place功能,我终于能够做到了。
我会发布代码,以防有人需要类似的东西
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;
}
和结果