- Home /
Pathfinding and AI for an RTS game
Hi Everyone, I've been looking around for a way to implement path-finding and AI into my game, but everything is leading to tools that have already been created which is not what I want to use. I instead want to create a custom AI and path-finding system so i have complete control over how everything behaves in my game which is a vision in itself
What I need it to do is listed below
Navigate around obstacles
Allow me to take control of every single unit created in game, but one at a time so I can implement proper FPS elements
I can select a unit or lots of units and tell them to go to a single point and if its a large group, know to go to that point but not crowd around it until the unit that reached that point moves
Be intelligent enough that I can tell them if they should or shouldn't attack something
have some form of UI to it
A way to command a unit to build or research something
How would I even begin to go about doing this, I've never played around with AI before and I would die happy even if I could implement path-finding without relying on any bought or downloaded tools from someone else.
Google and multiple years of experience coding. Path finding is one of the most complex aspects of game coding. I suggest you start with a downloaded tool, there plenty of free ones out there. Once you are familiar with the basics you can start your own implementation.
Yeah, I haven't even been able to find any tutorial for how to write pathfinding. I made my own using trigger volumes in a grid pattern using raycasts, but if I had more than a few enemies at once, it lagged, showing how inefficient it really was. I would like to know how to write proper path-finding myself, for self-improvement purposes.
$$anonymous$$y opinion is that you shouldn't worry about reinventing the wheel unless you can revolutionize it.
Program$$anonymous$$g Game AI by Example by $$anonymous$$at Buckland is an excellent beginners/intermittent resource for diving into the concepts behind AI driven systems and how to implement them.
I suggest reading about the fundamentals of AI and what sort of components make up good AI before you start coding something.
Why would I reinvent something? I just want to make my own AI and path-finding. If its difficult then it will tell me a lot about coding.
Answer by HarshadK · Jun 04, 2014 at 06:33 AM
For pathfinding there are great bunch of algorithms that you can use. Of course you also need to modify these algorithms to suit your needs.
Basically A* is the prime choice when it comes to the pathfinding and it has been widely used in the past also.
But recently I came across the algorithm used in Supreme Commander 2. As per the devs they have used Flowfield algorithm based on Continuum Crowds paper by the University of Washington for their AI in the game. The demo link for the AI and the link for Continuum Crowds.
You might also find this helpful for your work.
You can also search for tons of articles over how some of the best RTS games have implemented their own pathfinding and AI in their game.
And the list just goes on. If you are really serious about implementing all this by yourself (which I don't suggest as @Infiniteno said, do not reinvent the wheel) then you are up for a really tough journey and if you succeed then for a great treat by the end.
Thankyou for the optimism and the encouragement. Who knows, I might see you playing it someday and you can tell me what you think yourself
Answer by Tarlius · Jun 04, 2014 at 06:12 AM
The people saying you shouldn't rewrite stuff are correct.
However, if you want to do it anyway as a learning exercise or something, you should still look at existing tools! By using the tools you will probably run into the names of algorithms that you should take a look at, and can see what they do well and what you can improve on.
Off of the top of my head, I think you'll probably want to look at "A*" (I think wikipedia has a nice animation demonstrating it) and "the travelling salesman problem" for pathfinding, and read about state machines for a starting point on AI.
If you need to "take control" of a unit, you will probably want to keep the input interface the same for fps and AI. The Unity robots example project has some good examples of this. If you keep a common interface between the two you will be able to swap out the controller more easily at runtime.
I'll say it again though- I don't think anything you said you want to do is a reason to reinvent the wheel, unless purely for learning purposes. I would imagine that AI and Pathfinding are areas easier than most to get bogged down trying to optimise to a playable level and bugfix.
Well lets call it a learning exercise then, I'm not looking to reinvent the wheel, i just want my own custom path-finding and AI so I don't have to worry about licenses or anything because I plan to sell this game and make it my career and my life's work. Though thank you for the advice.
Anything you buy on the asset store you can use in a game you sell. As for other code... Its much easier to check what their licenses allow than to do this stuff from scratch... To get the kind of performance and quality you see in (good) released games will take a lot of effort! Custom =/= better.
But if you do go that route, I wish you the best of luck! :D
There was a Unity presentation a while back about optimisation of birds flying close together that might be worth a look. How much optimisation will be required to get to "good enough" will depend on how many units you'll expect in a game/etc though of course...
Answer by mossman3333 · Jul 02, 2014 at 10:00 PM
I took a free online ai course from Edx. They use python, but the concepts are universal. I see that it's still up, but in archive mode. I really liked their instruction. If you are trying to learn A*, they present it well; step by step.
there's a link: https://www.edx.org/course/uc-berkeleyx/uc-berkeleyx-cs188-1x-artificial-579#.U7SAaPldV8E
Your answer
Follow this Question
Related Questions
AI Pathfinding In A Certain Height 1 Answer
RTS Grid and Pathfinding 2 Answers
RTS dynamic formation width and length 0 Answers
Moving multiple AI units as one for RTS game. 1 Answer
Object move back to first position 4 Answers