首页 > 解决方案 > 我无法使用 (point_distance) 杀死靠近我的英雄 GMK 的任何敌人

问题描述

我在 Game Maker 程序中的代码有问题 我制作了一个小游戏,其中有一条敌人走的路径并将英雄放在他身边,当敌人接近他时,他转向他并射击他 我正在使用这个代码

var ex, ey;
ex = instance_nearest(x, y, enemy).x;
ey = instance_nearest(x, y, enemy).y;

if point_distance(x, y, ex, ey) < 150
{
     image_angle = point_direction(x, y, enemy.x, enemy.y);
}

代码运行良好,但问题是我的英雄只有靠近他们时才会去第一个敌人,即使第一个敌人超出范围也不去其余的地方有什么解决办法,请拍照说明 英雄忽略附近的敌人,只前往游戏中出现的第一个敌人

标签: xcodegame-makergml

解决方案


您正在检查正确的敌人,但没有指向正确的敌人。改为存储找到的实例 ID,并将其用于所有人:

var e;
e = instance_nearest(x, y, enemy);
if (e != noone) { // wouldn't want to crash when you run out of enemies
    if (point_distance(x, y, e.x, e.y) < 150) {
        image_angle = point_direction(x, y, e.x, e.y);
    }
}

推荐阅读