Advice on my 2D Pathfinding solution

Currently I am programming a 2D RTS-style game. Obviously in RTS games there is quite a bit of pathfinding going on. I am writing my code now, but I was concerned that it may not be the best solution (as I always am), so I thought I would see if anyone had any advice on my procedure.

Currently when a character is selected and given a position on the map to move to it goes through these steps:

  1. Shoot a Raycast out in three directions. If the AI’s movement is to the right I set the vectors direction to (0,1,0), (1,1,0), (-1,1,0).

  2. If Raycast hit returns true against a GameObject tagged as “Wall” I then create a grid of nodes and set the starting node and the final node.

  3. Finally I perform A* to find the quickest path from the starting node to the final node and return an array of Vectors for the AI to follow.

This is what I am currently building. I don’t particularly have any questions about how to code this process, but rather is this a viable solution for a video game that may have up to 20 different AI moving on the screen at once? Thanks for any input and suggestions in advanced!

why reinvent the wheel…

http://www.arongranberg.com/unity/a-pathfinding/

I guess I never think to use other people’s code. It can be a good thing at times and a detriment at others. Thanks for the help! I’m sure this will be ten-times more efficient than what my code is.

Yes it will be, and will save you a lot of time! Aron’s pathfinding library is the best out there for Unity.