简体   繁体   English

Game Maker中的敌人重叠:工作室,我该如何解决?

[英]Enemies Overlapping in Game Maker: Studio, How Do I Fix This?

The AI of my enemies that I made for my game is simple. 我为游戏制作的敌人的AI很简单。 They just follow the player (more precisely, they look in the direction of the player and go forward) 他们只是跟随玩家(更准确地说,他们朝玩家的方向向前看)

    Step Event:

    if (instance_exists(obj_player)){
         direction = point_direction(x,y,obj_player.x,obj_player.y);
    }

    speed = spd;

But they keep on overlapping each other and go on top of the player. 但是他们继续互相重叠,并超越了玩家。 I've tried researching but all the forums said was to use place_free() and xprevious & yprevious, but I have no idea how to use them. 我曾尝试研究过,但所有论坛都说过要使用place_free()和xprevious&yprevious,但是我不知道如何使用它们。 How do I fix this? 我该如何解决?

Thanks :) 谢谢 :)

You can read about this on the gamemaker documentation : https://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_free.html 您可以在游戏制作者文档中阅读有关此内容: https ://docs.yoyogames.com/source/dadiospice/002_reference/movement%20and%20collisions/collisions/place_free.html

basically, what you want to do is avoid moving your instance if that means causing a collision. 基本上,您要做的是避免移动实例,否则会导致冲突。 x_previous and y_previous will be used to cancel the move by going back to the previous position. x_previous和y_previous将用于通过返回到上一个位置来取消移动。

But I think it's better to check the place before moving, so I would add at the end of you script : 但是我认为最好在移动之前检查一下位置,因此我将在脚本结尾添加:

if (place_free(x+hspeed, y+vspeed)) speed = spd;
else speed = 0;

that way, the ennemy will stop instead of stepping above an other instance. 这样,敌人将停止,而不是超越另一个实例。

A little upgrade would be the following : if there is a collision detected, check if you can move along a single axis instead (x or y) and do it. 以下是一个小小的升级:如果检测到碰撞,请检查是否可以沿单个轴(x或y)移动并进行操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM