- Home /
(ideas, resources) RTS AI create its own waypoints without pathfinder
Not asking for fixing code, just for your thoughts your pdfs and your resources. (gimme!)
I'm trying to create a tactical, 2d fleet-based space combat. Similar to Distant Star: Revenant Fleet. For now, among other things, I have a waypoint system in place, so player can select some ships, place waypoints around and they will work their way through each of them. (No, it wasn't simple, the game is heavily employing newtonian movement)
No pathfinding is used whatsoever and I'd like to keep it that way, as there will not be many units on each map, and avoiding collision via boids based algorithm works perfectly.
But, how would I go about making computer create it's own paths? I'd like the AI to be able to flank my ships or herd my ships to trap, or etc. I thought about using boids again, make the AI avoid my stronger ships while seek for weaker ones, so then a weak, say destroyer will try to stay clear from battlecruiser, but will fly around it to get to the frigate. (Only rough idea how to code even this but there's hope)
I don't want to make it too performance hungry, or spend months redoing it again and again. Hence the post.
Answer by Lahzar · Jul 18, 2015 at 09:47 PM
I hate breakin' it to ya, but this is technically pathfinding. The socalled "boids based algorithm" youre talking about is just realtime pathfinding. Its less efficient than proper pathfinding, but it doesn't impact performance because its not used that often.
Now heres the thing about tactics. You can do tactics without having a proper pathfinding system involved, but its going to impact performance like nothing else! And its going to be awfully complex! So do yourself a favour. Get A*. You could follow this guys tutorial: https://www.youtube.com/channel/UCmtyQOKKmrMVaKuRXz02jbQ Or get the Aron Granberg A* Project, which is really really really good! And it has a great community! Its really really efficient and you can have thousands of agents before your game starts to lag!
So I understand you might have a problem when you incorperate physics to A*, but you can still do it. Especially if you already have a system of how to move the ships around, like your waypoint system! Some tactics wont work unless you utilize all nodes, so I would recommend you use a navmesh and do some research on pathfinding on navmeshes! (See first link, bottom of answer) You have to do some clever stuff I wont talk about to make it work on navmeshes, but its doable! A navmesh is just an A* grid where it removes most of the nodes and only keeps the ones essential to creating a mesh, or oppsite; creating just the essential nodes from a mesh!
To the theoretical part: This is how most tripple A games do tactics. They have a navmesh or an A* grid. These types of grids contains different positions aka nodes. Nodes are different from game to game, but what they all have in common is the concept of costs. You should do some research on A* pathfinding to understand this better (https://www.youtube.com/watch?v=-L-WgKMFuhE Really really good video series!), but what you need to know is nodes with lower costs are prioritized!
So how would you use this? Easy! You want to do some research on tactical pathfinding and tactics and find your own creative ways of doing different tactics, but here are some examples:
Basic Flanking: You have a coroutine running in the background of your game (coroutines are awesome for perfomance) which raycasts from the player to every single node every X millisecond, and returns the angle, and the visibility of each node. If a node is greater than angle X, compared to the forward director of the player, then we know the node is in flanking position! So we can increase the cost of every node that is infront of the player! This means the AI will always be more likely to move to move to nodes that are beside/behind the player. Bam! Flanking!
Tactical pathfinding: You can increase the cost of every visible node, and the nodes that are in the players line of fire even more to get some nice tactical pathfinding going. This means the AI will avoid the players line of sight, and they will try even harder to avoid the players line of sight.
If you wanted to do this without a proper pathfinding system, you'd have to like raycast from the player and X degrees to the right and left and create a random point inside the large circle youve just made to create a potential flanking point.
Most of this I learned from a book called Game AI Pro: Collected Wisdom of Game AI Professionals. I would really recommend it if you want to make a good AI, and youre really serious about it. There are 2 and they are both very expensive, but so worth it! I just happened to find a chapter that covers this in great detail for free on the internet! (Link below, read the heck out it!)
Refrences:
Game AI pro: http://www.gameaipro.com/ (Available on Amazon)
Specifically chapter 4.4 or 29: http://www.cgf-ai.com/docs/straatman_remco_killzone_ai.pdf Experience & some of my posts