GML -> 检查碰撞实例的变量,然后执行操作
GML -> check for a colliding instance's variable, then do action
我一直在尝试编写一些 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
}
这是一张描述我想要得到的图像(请注意,敌人知道他们应该攻击,即使他们没有与主角直接接触,只是因为除了敌人之外正在攻击)
多亏了instance place功能,我终于做到了。
我会 post 代码以防有人需要类似的东西
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;
}
和结果
我一直在尝试编写一些 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
}
这是一张描述我想要得到的图像(请注意,敌人知道他们应该攻击,即使他们没有与主角直接接触,只是因为除了敌人之外正在攻击)
多亏了instance place功能,我终于做到了。
我会 post 代码以防有人需要类似的东西
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;
}
和结果