Friday, July 15, 2016

actionscript 3 - Algorithm to make groups of units


In Age of Mythology and some other strategy games, when you select multiple units and order them to move to some place, they make a "group" when they reach the desired location:


Group


I have a Vector with several sprites, which are the selected units, the variables tarX and tarY are the target x and y. I just want an example, so you can just set the x and y position and I can adapt it to my code. Also, I would like to ask that the algorithm calls "isWalkable" for the x and y position, to determine if it's a valid position for each unit.




Answer



What you're looking for is basically coordinated movement. The units pathfind to their destination and when they reach it, they form a "formation".


This is a topic decently covered in the AI Game Programming Wisdom (Book 1, Book 2, Book 3 and Book 4) books. But, I'll refer you to the following articles:


Coordinated Movement - A link explaining the fundamental principles of coordinated unit movement in RTS games


and


Implementing Coordinated Movement - An article continuing from the first, that talks about how to implement this type of movement in a game.


It's written in C++ but it shouldn't be too difficult to port to any other language, as the underlying principles remain the same.


Hope that helps.


Ray


No comments:

Post a Comment

Simple past, Present perfect Past perfect

Can you tell me which form of the following sentences is the correct one please? Imagine two friends discussing the gym... I was in a good s...