Questions for using A* PP in a 2D top-down RTS

So I’m quite new to the A* Pathfinding Project, but would like to use it for a game of mine. I have some questions but don’t want to blast a reader with “how do I make this game”? So instead I’m going to quickly outline my goal, list out the questions, and then give my best idea as to what the answers would be. If anyone has tips, or a better idea as to how to solve any of these, I’d greatly appreciate hearing them.

My current plan is to put together a top down 2D RTS, similar in gameplay to the Pikmin series.
Here’s a visual reference: https://www.youtube.com/watch?v=Sf7kUedUiWY&ab_channel=IGN

Basically, there will be lots of little units either following a player controlled character or performing tasks throughout a moderately large 2D map. These units will need to path around level geometry when following the player character, and will need to path back “home” when carrying objects.

The player character is controllable through the gamepad, but can be instructed to move to a specific location. Control will be “taken” from the player and the character will then path-find to the selected position.

So here are my questions:

  1. Given the need for a large, moderately complex 2D level, which graph type would be best?
  2. How do I directly control the player through the gamepad?
  3. How would I implement different hazards/routes that different unit types would know to avoid/use? For example, water that Blue Pikmin can cross, but others will attempt to avoid.

And here are my best guesses:

  1. I would assume that a recast graph is optimal given the needed size of these levels. I am aware that a 2D recast graph will be available in the next beta release.
  2. I tried using AIPath.Move and then FinalizeMovement to control the player character, but even with “constrainInsideGraph” set to true, it was moving off the graph. I was using a GridGraph in this scenario, so maybe something was wrong there? I’ve read that using an RVOController might be the best way to handle direct movement? The player doesn’t really need object avoidance. They just need to be properly constrained to the graph 24/7.
  3. I would assume that generating different graphs for different units would be the best option here? In the Blue Pikmin example, I just generate a version of the map where the water DOESN’T cut a section of the graph.

Again If anyone has better solutions, I’d love to hear them. Thanks.

@aron_granberg I apologize for pinging directly, but it would be great if I could hear your take :slight_smile:

Hi

  1. If it is large enough, a recast graph is the best, otherwise a grid graph works well too (especially if you want additional tags and penalties, a grid graph is the way to go). If the game uses 2D colliders, then you’ll have to wait for the next beta update before those can be used with the recast graph. The grid graph supports both 3D and 2D colliders already.
  2. You can either disable pathfinding entirely and do the movement yourself, or you can continuously set the destination of the agent to a point a few meters away from the character, in the direction you want them to move.
  3. This is done using either having multiple different graphs (see Multiple agent types - A* Pathfinding Project) or by using tags (see Working with tags - A* Pathfinding Project). Note that using tags with penalties are not very accurate on recast graphs. Grid graphs lead to more predictable penalties. If you only need regions where the agents can/cannot walk, without any penalties, then both recast and grid graphs work well.

Thanks for the response :slight_smile:

For #2 I’m just not sure how to constantly constrain the character to the graph surface. I would definitely like to add things like wind or other displacement forces that affect the player both when they’re controlling the player character, and during pathfinding. I’m just a bit confused since Unity’s NavMesh agent keeps the gameobject on the nav mesh surface EXTREMELY tightly, and has a very clear “SetDestination” and “Move” method for telling it when to pathfind to a specific location, and how to apply forces respectively. What’s the equivalent for the A* PP?