xcode - 我无法使用 (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);
}
代码运行良好,但问题是我的英雄只有靠近他们时才会去第一个敌人,即使第一个敌人超出范围也不去其余的地方有什么解决办法,请拍照说明 英雄忽略附近的敌人,只前往游戏中出现的第一个敌人
解决方案
您正在检查正确的敌人,但没有指向正确的敌人。改为存储找到的实例 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);
}
}
推荐阅读
- accessibility - 复杂的 aria-live 计时器进度条焦点完成加载和消息问题
- python - 无法使用 ajax 将 json 显示为 html
- mysql - 使用 spring jpa/vaadin 访问关系数据库
- java - 从文件末尾删除哈希
- angular - 我如何让 postcss 和 sass 一起工作以便顺风工作
- excel - 按计数拆分行并使用 VBA 将其粘贴到单独的工作簿中。出现语法错误;缺少运算符
- node.js - 使用 Typescript 使用 Node.js 设置 react.js
- python - 解决 AWS 假设角色会话到期问题
- javascript - onChange 反应原生
- r - R中是否有一个子集函数可以让我平衡子集和条件?