🎉 Celebrating 25 Years of GameDev.net! 🎉

Not many can claim 25 years on the Internet! Join us in celebrating this milestone. Learn more about our history, and thank you for being a part of our community!

Group Movement...

Started by
9 comments, last by ragonastick 22 years, 9 months ago
I''m currently rewriting my pathfinding module of my RTS for the third time, and basically, I''m wondering what ideas you have for setting up good looking group movement. To give you a few details, the maps will not necessarily be full of wide open spaces, which seems to put things in a bit of a bottleneck. I don''t need to have formations, so that is not something to worry about. My main problem is that I''m not sure how much of the path to work out when the user gives the order, since by the time a unit gets to another location, the map will probably have changed (with units moving about). My first attempt was just your standard A* algo, and whenever it got to an obstacle which was not supposed to be there, then the entire path was recalculated. This had a few problems, I didn''t like the short pause when the new path was found, and also because it didn''t adapt to the environment unless it was absolutely necessary, then it would dodge non-existant objects which were there when the path was calculated. Second attempt, I decided to use A* again for the main path and ignore any dynamic obstacles (such as units), but every move, instead of following that path, I would look ahead 5 or so moves ahead based on the original search, and then make the first of those moves. This was better, but slow, and sometimes ended up with a situation where looking ahead 5 moves would not find a path, which also led to a nasty pause. But bigger problems came when dynamic obstacles which were ignored when calculating the master plan path were blocking the path and they didn''t actually move, or they did move, but they still blocked the path, so the path found would be void. I figure that I am probably going to have to live with having pauses and stuff as the map changes since it is a fairly tricky thing to do but... any ideas? The reason I title this Group Movement is because one of the main collisions I was having was having was two units both heading for the same location and trying to take very similar paths.... and also, because there are lots of pathfinding threads right now... and this one is different For the record, I have also read the excellent articles at Gamasutra about how this was handled in Age of Kings... they were a good read, and I''ve learnt a lot.. the main differences I have to their problem is that my terrain will be a lot more maze-like, no need for formations and also the way things are designed, collisions can never happen in my game: if two units end up on the same square, one will disappear, which means that my pathfinding has to work coordinating the movement through squares rather than telling the units to move from point A to B and then resolving collisions as they happen. Sorry for the verbosity in describing my qualm.... all my questions seem to turn out this way Trying is the first step towards failure.
Trying is the first step towards failure.
Advertisement
Check out Steering Behaviours by Craig Reynolds. Its an online article so you can find it on a search engine. Its got everything you need.

Heres the page:

http://www.red3d.com/cwr/

Edited by - Davaris on September 19, 2001 8:17:03 AM
"I am a pitbull on the pantleg of opportunity."George W. Bush
Just quickly, I''m going to take this opportunity to go slightly off-topic:

Why don''t you have your units head in a GENERAL direction towards their target, but only path to the places in their line of sight? It would seem more realistic, and not as heavy on the pathfinder.

Now back:

As for group movement, just use flocking. You just need each unit to have a direction vector, a distance to other units value and a distance from other obstacles value. You can also have a distance to group leader variable.

That way, they move in the same direction, keep a certain distance from one another (in formation) and if the end up in a bottleneck, they move into a line, still in closed ranks. Once they get back out in the open, if you have a distance to group leader variable, they will move back from a ''line'' to more of a group/circular formation.


"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick

"It is far easier for a camel to pass through the eye of a needle if it first passes through a blender" -- Damocles
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
quote: Original post by Merrick
Just quickly, I''m going to take this opportunity to go slightly off-topic:

Why don''t you have your units head in a GENERAL direction towards their target, but only path to the places in their line of sight? It would seem more realistic, and not as heavy on the pathfinder.


This is really only more realistic if your units have no knowledge of the terrain. (ie, it is the first exploration) No intelligent entity is going to head north to get to where its going when it knows the only way through the mountains is to the east. Know what I mean?
So it would appear to me that your problem is not one of pathfinding, but rather one of replanning.

If you think of a path to walk as a set of movement commands - e.g., turn to heading theta and walk at a speed of V - then your units are executing plans that take them from a start state to a goal state. Pathfinding is just a very specialised form of planning that is implemented as search.

When your agents are executing their plan, the plan will be successful unless one or both of the following occurs: a) the outcome of a given action is not as predicted when creating the plan; and/or, b) the world has changed in such a way as to invalidate the plan.

In either of these cases, the plan is said to have broken. You will need to replan. This does not mean creating a whole new plan from the current state. Indeed, that sort of replanning is only necessary in the worst case scenario.

Before going down the ''new plan'' path, the better (and computationally cheaper alternative) is to try and repair the old plan. In other words, find the cheapest action sequence that gets from the broken state back in to a valid state of the plan. Obviously, you also want to choose a state that will not lead directly back to the same broken state. In terms of pathfinding, this might mean finding the shortest route around an obstacle to where the original ''path'' emerges on the other side.

The other alternative is to perform predictive replanning. This is quite tricky and requires a knowledge of the sorts of events that can take place in the world and their likelihood (probability). Whenever the agent obtains new information that the world is not as it was when it made its plan, it predicts the outcome of its current plan given this ''new world model''. It then alters its current plan (by either splicing in extra actions or finding a complete new plan where the former is not possible) before it arrives in the predicted broken state.

My suggestion for your problem is simply to repair your plan when it breaks. Here is one way to do it. Associated with the original plan is a section of the state space that the plan takes the agent through. The plan breaks when the path through this section of state space is ''blocked''. So, look ahead in the plan and compare it to the new state space (ie, the new world model) and find the first state that is not blocked. In terms of pathfinding, find the nearest point on the current path segment that is not blocked and then perform a search for a path from the current spot to that spot.

Computationally this will be far cheaper than performing a new search from your agents current state. Unfortunately, the downside is the the unit movement want ''look'' overly intelligent, in that it will insist on going to just the other side of the object before taking up its plan again. You can tweak this method a little by making your units cut corners where possible. This will tend to smooth out their path and make it look a little more intelligent.

I hope these thoughts have helped.

Good luck,

Timkin
Thanks a lot for the replies, any ideas are going to help me right now

Just think I might make one other thing clear, the realism does not matter at all. If the path found is always perfect, there is no problem with that because of the world the game is set in (it is totally abstract so it doesn''t need to follow any of our worlds rules) but on the other hand, a non optimum path is also quite acceptable, as long as it is consistent which it will be since it is the same computer doing the same algorithm.

I was just out in the kitchen, and I noticed some ants getting some food from somewhere (don''t tell the health inspector ), and... I think the term is something along the lines of collective intelligence and you know what? I think it would be a pretty neat thing to model. Think of it as the GA of pathfinding. One ant finds a path and uses it, other ants follow the first ant, but also occasionally move off it and sometimes shorten the path, if that happens, the other ants will also follow the new path.

Repairing the path is something I hadn''t really considered, and doesn''t sound too difficult. Do you have any experience with this because I would like to know a few things, mainly about the end result. What I *think* will end up happening is that if you have a group of agents all moving from near point A to point B, then there will be a lot of repairing and shuffling at the start, and then they will assume a kind of single file line. If that is the case, I might just try and calculate one path and tell the other agents to follow the leader.

Which brings me to the next problem with repairing. Take this situation:
XXXXXX......A..W.B......XXXXXX. - walkableA - start nodeB - finish nodeX - wallW - wall 


If a path was to be calculated here from A to B. It would have to avoid wall W. Now, if wall W is destroyed after the path is found, the path is quasi-broken. The path still works, but it will look a bit stupid, dodging a non existant wall. But how to judge whether the path is broken or not? (to clarify, although the path can be unrealistic, it should not look to be outright stupid to the user, if it finds the perfect path, that is possibly unrealistic, but if the path found is not the best, it should at least not have glitches which seem totally illogical for any world)

I kind of like the idea of the ants though, maybe dropping "food" for successful paths, and sending out an army of invisible ants ahead of the unit. If it was fast enough, ants could constantly be moving back and forth between the agents reinforcing paths or improving them as things change. Papers anyone?

That website; http://www.red3d.com/cwr/ is really handy, thanks for that. Now the problem comes in trying to implement a few of those things with a path. Not impossible, and will look quite good if done... I''ll see what happens.

Trying is the first step towards failure.
Trying is the first step towards failure.
quote: Original post by ragonastick
Repairing the path is something I hadn''t really considered, and doesn''t sound too difficult. Do you have any experience with this because I would like to know a few things, mainly about the end result.


Mmm, you could say that I have some experience with replanning. It''s the basis of my PhD research in which I developed some of the ideas I mentioned in my previous post. My domain was a lot tougher though - that of a fully autonomous robotic aircraft performing meteorologial reconnaisance.

quote: Original post by ragonastick
What I *think* will end up happening is that if you have a group of agents all moving from near point A to point B, then there will be a lot of repairing and shuffling at the start, and then they will assume a kind of single file line. If that is the case, I might just try and calculate one path and tell the other agents to follow the leader.



How you get units to move relative to each other depends on whether you intentionally group them or not. My suggestion here is - that given you expect lots of obstacles - implement a flocking behaviour to ''coordinate'' movement of several units at once. The general path they follow can be determined by your planning algorithm.

Now, let''s consider the problem of the ''destroyed wall''. First of all, you have an ''event'' occuring that changes the world. This can be used as a trigger for considering whether replanning is necessary or not. You have some things to think about if you choose to consider replanning after an event. What you do will depend on how the event affected the world. If the event altered the state space so as to block the path, then you will need to consider what I wrote in my previous post. If however the event ''opened up'' a region of the state space (as in your example) then you need to consider two actions: 1) Perform the whole pathfinding task again, or 2) ask whether the current path can be ''improved''. As you have already seen, the first option is computationally expensive when considered against the timeframe for replanning. The second option is far less so.

The path can be improved if any set of segments of the path can be replaced by a shorter (read cheaper cost) segment. If the path is defined by a set of waypoints (which can be set as the locales of the end of actions) then you can do the following. Starting at the current location (call it point S) and skipping the next waypoint in the plan sequence, check to see if there exists a path from S to each successive waypoint. If such a path exists to waypoint wi, that has lower cost (or shorter distance if cost is a linear function of distance travelled), then set the next waypoint to be wi and delete all intervening waypoints. Iterate this procedure over all waypoints, remembering that the set of waypoints needs to be updated as soon as a shorter segment is found.


Good luck,

Timkin
Just quickly, I doubt your wall would be completely vaporised, so wouldn''t it have a higher movement cost (rubble, etc.) than the area around it? So the path deviating around it wouldn''t look so strange.


"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
"NPCs will be inherited from the basic Entity class. They will be fully independent, and carry out their own lives oblivious to the world around them ... that is, until you set them on fire ..." -- Merrick
Here is a bit of a ''weirder'' insight into a possible solution:

-Unit plans out path. Along that path (each movement increment) this unit actually places an invisible ''waypoint'' object. If a waypoint already exists somewhere along his path; this unit just adds his name or id or whatever.

-As your unit moves along his path, when he begins to head towards the next waypoint, he requests control of it, if he succeeds in controlling it; he moves towards it. If not, he can either re-calculate his path; or attempt to find another path. When he is not able to gain control of the waypoint; that means another unit already has control of it. After he leaves the waypoint, he relinquishes his control, and removes his name from the list. If all names or ids are removed from the waypoint, it can be deleted.

So far; that basically solves the multiple units along a similar or interesecting paths. If you let the units just wait until they can gain control of a waypoint; they will end up either falling into a line (if they are on the same path); or they will display coordinating behavior.

-As far as the dynamic ''collisions''; when the collision occurs, simply find the nearest waypoint(s), and send a message to each unit listed on that waypoint; whereas at that time they re-calculate their path.

The one problem I foresee with this solution is if your waypoints are fairly distanced and not aligned on common boundaries(i.e. not grid-like). If this is the case; you still may end up with various units running into each other; or paths from one waypoint to another being blocked. If this is the case; a possible solution would be to lock a ''box'' of waypoints off each movement. For example; lock all waypoints within a radius of the target waypoint.

Kind of a weird solution; but I think it may work out for you.

-mihkael
quote: Just quickly, I doubt your wall would be completely vaporised, so wouldn''t it have a higher movement cost (rubble, etc.) than the area around it? So the path deviating around it wouldn''t look so strange.

That was just an example, much more complex problems could arise if say the removal of the wall would create a totally new path.

quote:
Mmm, you could say that I have some experience with replanning. It''s the basis of my PhD research in which I developed some of the ideas I mentioned in my previous post. My domain was a lot tougher though - that of a fully autonomous robotic aircraft performing meteorologial reconnaisance.

I knew I could count on you having something like that under your belt

I''m trying to stay away from actually intentionally grouping them. But, I don''t have any reason why I can''t. But I would like it if say two groups had crossing paths, they would still look semi-intelligent.

This is why currently I am leaning towards doing something which is not necessarily perfect but really fast so I can do lots of updates. Also, a follow the leader type group movement should look fine (especially since there are lots of narrow passages). This will probably require me to somehow define waypoints. I saw an example on how to do that somewhere, so I should be able to track that down. This will probably be accompanied by a crude form of flocking (I say crude because units will move at fixed speeds, and although they might pause, once they move from one square to the next, they move at a constant rate until they get there)

Sorry if it sounds like I am completely disregarding your ideas, but my main fear is that having a system with all these events for things like destroyed walls could get slow. Every time a unit moves, it has the possibility of opening a new path, so if lots of units are moving at one time, there is going to be a lot of stuff happening - for each square the unit moves, all the other units have to check whether this will effect their path. Obviously I could make less checks based on proximity and frequency, but there would still be a fair few performance issues.

Also, I feel that I should be exploiting the fact that my pathfinding doesn''t need to be perfect... that''s what software development is all about .

Also, another idea I''m considering based on the title of a dead link I found was the concept of rubber bands, as being a deformable path. When you put a rubber band between 2 points, it will always be on a path, no matter how much you stretch it. And it ''encourages'' a unit to follow the shortest path but doesn''t enforce it. It might be too slow for my liking also though

Trying is the first step towards failure.
Trying is the first step towards failure.

This topic is closed to new replies.

Advertisement