A *算法的2D游戏径处理问题 [英] A* Algorithm 2D Game Pathing issues

查看:177
本文介绍了A *算法的2D游戏径处理问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经决定从早在一天拿起我的旧的2D游戏引擎,继续它的工作这是我试图执行一些基本的AI敌人的第一次尝试,我有一些问题。下面是一个关于如何我治疗AI的敌人跑了。

I have decided to pick up my old 2D game engine from back in the day and continue work on it This is my first attempt at trying to implement some basic AI for enemies and I am having some issues. Here is a run down on how I am treating the AI for enemies.

  • 如果玩家一定范围内的敌人中,敌人仅通过检查,看看他是向上或向下,向左或播放器的权利,并调整它的坐标相应走向球员。

  • If the player is within a certain range of the enemy, the enemy moves towards the player by just checking to see if he is up or down, left or right of the player and adjusting it's Coordinates accordingly.

如果敌人击中正在移动中的玩家的方向阻挡他,然后我打电话给我的A *算法,用于检测最短路径玩家和周围的障碍物移动的障碍。

If the enemy hits an obstacle that is blocking him from moving in the direction of the player then I call My A* algorithm for detecting the shortest path to the player and moving around the obstacles.

我检查,看看如果敌人不再受阻每一帧,并再次,如果是则调用A *算法来调整球员的移动位置。

I am checking to see if the enemy is no longer blocked every frame and if it is then calling the A* algorithm again to adjust for the moving position of the player.

我已经实现了A *的方式是我检查的基础上敌人的尺寸相邻的广场。因此,举例来说,如果我有一个60X60的敌人,我将这些维度内检查相邻的地砖,还敌人可以有不同的尺寸。我遇到的问题如下:

The way I have implemented A* is I am checking adjacent squares based on the dimensions of the Enemy. So for example if I have a 60X60 Enemy I will be checking adjacent tiles within these dimension, also enemies can be different sizes. The problem I ran into is as follows:

说的敌人是黑色的方形。它会检查它的相邻瓷砖,可以移动到方在它前面,因为它不与本方的任何物体发生碰撞。一旦它是在顶部正方形它可以通过适合向右方没有碰撞也。现在,对于这种情况:

Say the enemy is the black square. It checks it's adjacent tiles and can move to the square in front of it since it is not colliding with any objects in this square. Once it is in the top square it can fit through to the right square without a collision also. Now for this scenario:

假设A *算法被称为当敌人在黑匣子的位置。现在,因为没有需要的敌人顶端壁之间移动会有碰撞和基于我的算法的大小,这将导致忽略该块中的敌人。

Say the A* algorithm is called when the enemy is in the position of the black box. Now because there is not the size required for the enemy to move between the top wall there will be a collision and based on my algorithm this will cause the enemy to ignore this block.

所以,我的问题是,这将是解决此问题最常见的方式。有可能是一些愚蠢的我失踪,但我想我会问。我希望我解释这个问题我有做得不够好,如果你需要任何澄清,只是要求。先谢谢了。

So My question is, what would be the most common way around this issue. There is probably something silly I am missing but I thought I would ask. I hope I explained the problem I am having well enough, if you need any clarification just ask. Thanks in advance.

推荐答案

我假设你被敌人尺寸大小的块填充A *

这是错误的,你需要通过单细胞/像素喂什么都

that is wrong you need to feed by single cell/pixel what ever

使灌装填充相邻线的时候(不是整盒)

如果不能释放整个行,然后根本不填充

if not free the whole line then do not fill it at all

您需要连接code一些额外的信息,以A *图所示:

you will need to encode some additional info to A* map like:

  • 这是水平,垂直或两行
  • 如果是角落或盒位置

要知道哪种方式,你可以成长

to know which way you can grow

[注意事项]

A *灌装应该总是与你的运动能力

A* filling should always match your movement capabilities

这篇关于A *算法的2D游戏径处理问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆