View Full Version : Units movement in RTS
Roman Budzowski
08-19-2005, 03:21 AM
Hi
Do you know any algorithms for RTS units movement? I don't need A* algorithms, because in my simple game there is no terrain interaction. I just want my units to move smarter so units don't drive over each other. Let's say, there is 10 units on a screen with different states. Few of them run and may run over another unit or paths of two or more units may cross. I need algorithm (better than I did myself) that will let units to go around other units or keep them moving smooth if the paths cross (giving them new directions).
best regards
Roman
C_Coder
08-19-2005, 04:14 AM
I had your same problem and still had to use A* because of that. Then since I had A* I added terrain interaction :)
You have to recalculate each time you collide since other units can move and block the path that is currently active. Also make sure that you set add the Gcost of the blocks were a unit's path is so that other units can use other paths and not interrupt other units' paths.
I'm sure you'll understand what I wrote! :p
Nikster
08-19-2005, 04:16 AM
A simplish method to try would be to set your direction vectors towards your target, check the path you have chosen for n metres in front of you, if there is a blockage take the dot product between your path and the blockage and add the reflection of the dot product to your direction vector, that should take the shortest route around the blockage. I'd love to see it with a bunch of entities near each other, could be like pool where the balls try and evade the cue ball heh..
luggage
08-19-2005, 04:26 AM
Depending on how many units you have I implemented the Direct X birds demo code to do avoidance. Worked quite well.
ggambett
08-19-2005, 08:34 AM
I think what you need is called "flocking behavior". The bird sim sounds like a good start, but Google for "flocking".
Rod Hyde
08-20-2005, 01:35 PM
Last week, while researching something completely different for work, I was lucky enough to come across Programming Game AI by Example (http://www.ai-junkie.com/books/toc_pgaibe.html) by Mat Buckland. Chapter 3 covers the implementation of steering behaviours such as flocking, following, avoiding, etc, which is (I hope) exactly what you're looking for. The binaries and source from the book are all available here (http://www.wordware.com/files/ai/). The code from Chapter 3 demonstrates how to balance the different behaviours.
To get an idea of the guy's writing style and judge for yourself if you'll find the book useful or not, Chapter 2 (http://www.ai-junkie.com/architecture/state_driven/tut_state1.html) is available online.
--- Rod
sparkyboy
08-20-2005, 02:14 PM
Cheers Rod, that is indeed some KICK ASS AI!!!! :cool:
All the best
Mark.
vBulletin v3.6.0, Copyright ©2000-2008, Jelsoft Enterprises Ltd.