要做到这一点相当简单,您只需使用the distance formula 计算距离。您可以在 GML 中使用point_distance 函数。它看起来像这样:
if (point_distance(x, y, obj_player.x, obj_player.y) < r) {
//Move towards the player
}
其中“r”是您希望敌人跟随玩家进入的圆的半径。
更多信息,可以看这里:http://docs.yoyogames.com/source/dadiospice/002_reference/maths/vector%20functions/point_distance.html
不过,这计算起来相当昂贵(对于 CPU),因为它使用平方根函数。尽管对此的补救措施相当简单。您将编写以下脚本(我将其命名为 point_distance_squared,但您可以随意命名):
///point_distance_squared(x1, y1, x2, y2)
var x1 = argument[0];
var y1 = argument[1];
var x2 = argument[2];
var y2 = argument[3];
return (pow(pow(x2, 2) - pow(x1, 2), 2) + pow(pow(y2, 2) - pow(y1, 2), 2));
然后代码几乎相同,除了您需要将半径平方,它看起来像这样:
if (point_distance_squared(x, y, obj_player.x, obj_player.y) < (r * r)) {
//Mode towards the player
}