A * 2D Game Algorithm Problem Path

I decided to take my old 2D game engine from that day and continue working on it. This is my first attempt at trying to implement some kind of basic AI for enemies, and I am having some problems. Below is an example of how I feel about AI for enemies.

  • If the player is within a certain circle of the enemy, the opponent moves towards the player by simply checking if he is up or down, to the left or right of the player and corrects him. Corresponds to the corresponding coordinates.

  • If the enemy hits an obstacle that blocks their movement in the direction of the player, I call the My A * algorithm to find the shortest path to the player and move over the obstacles.

  • I check if the enemy is rotating every frame and if it calls the A * algorithm again to adjust for the player's moving position.

As I have implemented A *, I check adjacent squares based on Enemy's dimensions. So, for example, if I have a 60X60 Enemy, I will check adjacent tiles in this dimension, and the enemies can be of different sizes. The problem I am facing is as follows:

enter image description here


Tell the enemy that this is a black square. He checks the adjacent tiles and can move to the square in front of him, since he does not collide with any objects in that square. Once it is on the top square, it can fit into the right square without collision. Now for this scenario:

enter image description here


Let's say the A * algorithm is called when the opponent is in the black box position. Now, since the enemy does not need to move between the upper wall, a collision will occur 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 to solve this problem. Possibly something stupid that I am missing, but I thought I would ask. I hope I have explained that I have it well enough, if you need any clarification just ask. Thanks in advance.

+3


source to share


1 answer


I'm assuming you are filling A * with non-enemy sized blocks

what's wrong, you have to feed a single cell / pixel that ever

So when padding fills in adjacent row (not whole)

if you do not free the entire line, then do not fill it at all

A * with block filling



you will need to encode some additional information in the A * map, for example:

  • it is horizontal, vertical, or both.
  • if it is a corner or rectangular position

to find out how you can grow

[Note]

Filling A * must always match your movement capabilities

0


source







All Articles