Jump to content
alpha993

AI pathfinding to player's position inside a maze

Recommended Posts

lSpGBDP.jpg

 

So I built this maze in the Eden editor for a scenario akin to Daedalus and the Minotaur. The player is meant to start at the center and escape the maze while avoiding an AI who is actively hunting the player down.

 

However, Arma 3's existing AI pathfinding might as well not exist, since the AI simply phases through all the maze walls in a straight beeline towards the player. Ideally, the AI should find the shortest path (without phasing through walls) to get to the player's current position. This path would then be recalculated every few seconds to account for the player moving through the maze.

 

Any help on how this could be done would be greatly appreciated. 

Share this post


Link to post
Share on other sites

Are you referring to this script?

 

If so, that would require either building positions for the AI to move through, which the maze does not possess as it is made out of standalone castle walls, or hardcoded positions, which is not what I wish to accomplish.

Share this post


Link to post
Share on other sites

59nn1w2.jpg

 

wQSkzpC.jpg

 

This is a solution I thought of, but it kind of terrifies me from the amount of work that would be involved.

 

I basically built a grid of helper objects that the AI would move through, thereby avoiding the walls. Each helper would be synchronized to its adjacent helpers, in essence forming paths around the maze. I would then assign one to the AI as a starting position, from which it would travel along the synchronized helpers to the player's position. That's all well and good in theory, but I'm not quite sure how to actually go about calculating the route once that's done.

Share this post


Link to post
Share on other sites

sIwx0VY.jpg

 

So I ended up creating this grid of game logics which are synced-up together appropriately to form the paths in the maze. This way, the AI can walk along these lines and effectively simulate pathfinding without going through any walls.

 

In the meantime, I have it set up so the AI will simply randomly patrol the maze, but I believe it is easily achievable to use this set-up to run a pathfinding algorithm. Here's the code I have at the moment:

 

params ["_currentPos","_unit"]; //var name of starting position (game logic object), var name of patrolling unit (unit)

_lastPos = _currentPos;

while {true} do
{

	_synchPositions = synchronizedObjects _currentPos; //find all positions synchronized to the current position

	_nextPosArray = if (count _synchPositions > 1) then //check to ensure the unit does not backtrack unnecessarily
     	{
      		_synchPositions select {_x != _lastPos}
    	} 
  		else 
    	{
      		_synchPositions
    	}; 
	
	_nextPos = selectRandom _nextPosArray; //randomly select another position to move to

	_unit doMove getPos _nextPos; //make AI walk towards the new position

	waitUntil {_unit distance getPos _nextPos < 1}; //wait until the AI has reached the new position
	
	_lastPos = _currentPos; //register the last position for the next loop to ensure no unnecessary backtracking

	_currentPos = _nextPos; //update current position
	
};

 

What I have so far actually accomplishes what I was looking for, but any better solutions are always welcome. 🙂

  • Like 2

Share this post


Link to post
Share on other sites

You're going to have to create a graph model of your maze, after which you can apply shortest pathfinding algorithms such as A*.
These algorithms can be quite resource-intensive so you definitely do not want to run them on each frame.

 

I'm actually working on a dynamic graph-model representation of Arma's road systems, but my scripts are so specific for that that I don't think they'd be of much use for you.

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×