Sunday, September 10, 2017

Making the AI take different paths to each other


I have a top down 2d game where the AI spawn at the edges of the map and run towards the center.


I'm using A* and a node mesh to do the pathfinding.


Right now, the AI spawn at a point on the edge of the map and all take the same path which is the shortest route to the center.


Now I want them to be more surprising and interesting and take different paths to each other.


I can immediately think of two ideas for doing this but wanted to know if there are other ways or better ways that people often use?





  1. When one enemy spawns and generates a path to the center, temporarily increase the cost of all the nodes on that path, then slowly decrease them back down over time. Then the enemy AI that spawn later will be forced to take a wider path.




  2. The above approach will lead to AI just taking a wider and wider path though and still be very predictable. So I thought I'd also introduce a number of intermediate goal nodes around the map. When the AI spawn they randomly pick one of the intermediate goals and head there first before heading to the center of the map. Combining this with the above approach of increasing the costs might look pretty good?




What approaches have people found work best to getting the AI to vary the paths they take, look convincing and surprising?



Answer




Your second option hints at a more fundamental approach: ensuring enemies approach your player from different directions. The question is, how far do they have to travel to in order to get "around" your player? The ideal to this would be a mix of



  • dynamically generating points that closely surround (i.e. follow) the player's position;

  • what Nevermind has suggested in terms of randomising paths to these surrounding points, to a greater or lesser degree.


In this way, you can ensure that AI's won't take unecessarily lengthy detours just to get realistic path variation when converging on the player.


Collaborative diffusion does what you want implicitly as part of the algorithm. But it's non-trivial to implement.


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...