Welcome, Guest. Please login or register.

Login with username, password and session length

 
Advanced search

1411491 Posts in 69371 Topics- by 58428 Members - Latest Member: shelton786

April 25, 2024, 03:47:45 AM

Need hosting? Check out Digital Ocean
(more details in this thread)
TIGSource ForumsDeveloperTechnical (Moderator: ThemsAllTook)Crowd pathfinding
Pages: [1]
Print
Author Topic: Crowd pathfinding  (Read 3424 times)
meanwhale
Level 0
**



View Profile WWW
« on: November 11, 2013, 06:51:32 AM »

Does anyone has experience of programming crowd pathfinding? I think it's a nice and easy way to make game characters to find their path in a natural looking way, but I'm still missing some ideas how to improve it....

I uploaded a small crowd pathfinding demo of my new RTS game project. You can edit terrain, point units a target, and see how they find their way around in environment you created. Units don't use pathfinding algorithm like A-star, but instead try to walk straight to the target, and start wandering around obstacles when they meet them. Also they can ask their comrades to move, so that crowds don't get stucked in tight spots.

My goal is to make crowd movement look more natural and fun, unlike A-star for example, which makes units to move to the target optimal route. In addition, this way I avoid problems involved with changing environment and moving obstacles (i.e. other units).

Animation etc. are still quite rough but try not to care about it Smiley Give it a try and tell me your opinion! My future plans for the pathfinder is to make units to send signals when they are making progress towards the target, and on the other hand tell others if they are stucked so that other units nearby can make better decisions.

http://stonewallgame.appspot.com/
Logged

kamac
Level 10
*****


Notoriously edits his posts


View Profile
« Reply #1 on: November 11, 2013, 07:32:25 AM »

Looks nice. Would require some additional communication if it was an RTS game, though. For example, a team made out of five units wouldn't want to split, so one leading unit would have to choose the direction, and others would have to stick to it.

Looks way more natural, though.

@EDIT
Sometimes they're moving really dull, though. For example, four guys went straight to the point, while other got stuck at the wall and made a loop throughout the building to get inside  Tongue

Also, most of the time they're acting like they're blind Wink Trying to go into a wall instead of turning right where the space opens. You should probably add something like fore-seeing things.
Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #2 on: November 11, 2013, 08:10:48 AM »

Thanks, good points! I think they will look smarter when I add some communications between the units (signals between nearby units). They act quite similar when hitting a wall and hitting another unit. They should preferably wait for another units to move, instead of wandering around. But there's a lot of trial and error involved in tuning a pathfinder Smiley
Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #3 on: November 12, 2013, 09:50:37 AM »

I updated the demo. Now you can see in which state units are (text), and a red square where unit asks other unit to move from its way. Have fun Smiley http://stonewallgame.appspot.com/
Logged

BorisTheBrave
Level 10
*****


View Profile WWW
« Reply #4 on: November 12, 2013, 01:56:03 PM »

Unrelated, but I think "stonewall" is already taken as a name:

http://www.stonewall.org.uk/
Logged
meanwhale
Level 0
**



View Profile WWW
« Reply #5 on: November 13, 2013, 01:20:13 AM »

Thanks for heads-up Grin I thought it's quite a common name but I like it anyway, so maybe final name will "Defender of Stonewall" or something epic like that  Gentleman
Logged

NinthPower
Level 2
**



View Profile
« Reply #6 on: November 13, 2013, 07:47:40 PM »

You may want to also apply some Boids principles to help them stay together:
http://en.wikipedia.org/wiki/Boids
http://www.vergenet.net/~conrad/boids/pseudocode.html

looks cool!
Logged

Gregg Williams
Level 10
*****


Retromite code daemon


View Profile WWW
« Reply #7 on: November 13, 2013, 08:20:50 PM »

Generally the problem with just using basic steering is that they will get blocked forever if there are complex obstacle shapes. Like a "U" type shape, or a river that needs crossed via bridge, etc.

Logged

QCPolmer
Level 0
***


View Profile
« Reply #8 on: November 14, 2013, 01:31:12 AM »

Looks good.

They seem to be clumping up a lot... 
Maybe make a large non solid invisible box around each of them when they move,
 where if they overlap another objects box (Another moving object),
they try to move away from where the boxes intersect?
Like a reverse gravitational thing around the ones
that are moving.

Also, maybe set up blocks that the crowd could walk over
that work as pathways. 
(like either go up or go down while over this block )
This would keep the crowd away from the walls at times.




Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #9 on: November 14, 2013, 10:47:20 AM »

Good points! I have to explore that Boids thing more Smiley

I think it's a good idea to make AI work different depending on game character's type. For example some swarm-like crowd could use simpler, more straightforward algorithm than smart ones. Also, some characters could have more personal space, whereas others tend to clump up. It gives game characters personal traits in addition to graphics. Crowds controlled by the player should act quite straightforward. It's so frustrating if a group controlled by you try being too smart but end up doing something stupid  WTF
Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #10 on: December 09, 2013, 06:57:51 AM »

I have improved my crowd pathfinder quite a bit! I got ideas from ant pathfinding where ants spread out pheromones when they find the target, and then others follow the pheromone traces. In my solution pheromones are replaced with something I call beacons. Group of units start wandering towards a target. When some unit finally finds it, a beacon is set to the point the unit see it. And when some other unit sees that beacon, another beacon is set. Then group members can find the target by following the beacons. Beacons have a priority (B0, B1, B2, …) which tells how close to the target a beacon is.

I’m not sure if others use this kind of a technique, but it seems to work quite fine! The crowd moves naturally and usually most units find the target quite quickly after one has found it. Small groups can still get stucked in corners and do some merry-go-round, but that’s just lack of fine tuning...

Go check it out!

http://stonewallgame.appspot.com/
Logged

nikki
Level 10
*****


View Profile
« Reply #11 on: December 09, 2013, 08:52:35 AM »

I''ve had some success of combining the steering Boids things with A* in the past.
just make the boids follow a path (one of their features(arrive at)) that you've generated using a*

Logged
meanwhale
Level 0
**



View Profile WWW
« Reply #12 on: December 09, 2013, 12:18:30 PM »

My aim was to make crowd movement towards target look natural, rather than be efficient. Now the units seem to find their way around simple obstacles but they suck in labyrinth solving. That's where A* is the way to go. Crowd pathfinding's advantage over A* is that it doesn't need heavy pre-computing, which could be a showstopper if there's a large group of units who wants to call A* all at once. In addition units act naturally when environment changes, i.e. road blocks appear and disappear, and other units move on unit's way. Changes don't affect on crowd pathfinding whereas A* need recalculation.
Logged

diegzumillo
Level 10
*****


This avatar is so old I still have a some hair


View Profile WWW
« Reply #13 on: December 09, 2013, 12:53:43 PM »

I once implemented a crowd navigation system that works by first calculating a 2d field. My implementation was crappy but this type of algorithm has the advantage of costing the same (almost) independently of the number of units. It does depend on the size of the terrain though.

Old video I made:



edit: forgot to mention, if you want to know more about this method I can find you the papers I used!
Logged

Decent Machine
Level 0
**



View Profile WWW
« Reply #14 on: December 09, 2013, 03:32:48 PM »

Take all units as a "mass", find the closest unit in the mass to the target position. Run an A* for that person to the target. Run an A* from rest of the unit's to the closest unit and stitch together the whole path for all. If a unit is too far away (some threshold) from the center mass, let them run their own A* to the target. Now add some steering behaviors to the group along the path and you got something that can work for both open areas and small corridors.

It is at least one way to go about it, where you save a lot of performance because the paths from the units to the closest unit will be rather short. Is it easy to get right? NO  Cheesy
Logged
nibelheim
Level 0
**



View Profile
« Reply #15 on: December 09, 2013, 03:39:21 PM »

This is really cool.  Two things come to mind:

Swarm Behavior:
I've seen some videos and read some articles on swarm behavior in nature (http://en.wikipedia.org/wiki/Swarm_behaviour#Mathematical_models).  I wonder if that might be useful here?

Ted Talk:
I remember a Ted Talk on AI (although I can't find it) that showed an example of robots that appeared to express social behavior when in a room together.  It turns out it was all a simple light-censor response algorithm.  But the affect was to make it appear like they were moving like humans did in crowds, even being "polite" and waiting for one another.  If you could dig up that video it might help.
Logged
doihaveto
Level 2
**



View Profile
« Reply #16 on: December 10, 2013, 08:23:48 PM »

Does anyone has experience of programming crowd pathfinding? I think it's a nice and easy way to make game characters to find their path in a natural looking way, but I'm still missing some ideas how to improve it....

I uploaded a small crowd pathfinding demo of my new RTS game project. ... Units don't use pathfinding algorithm like A-star, but instead try to walk straight to the target, and start wandering around obstacles when they meet them.

Oh man, there are so many interesting ways to do this stuff, some of which I've done, others I'm looking for an excuse to do... Smiley

Off the top of my head:
  • Potential fields + edge following. As you mention above (go towards goal until you hit an obstacle, then follow the obstacle edge until you get a clear line of sight). It's so simple, and works surprisingly well in many cases! I do like solutions based on potential fields, like this one, a lot. But it can get into weird failure cases, like going around a column without ever getting a clear line of sight to the goal...
  • Flood-fill + density. This one is for the case when there's one destination that everyone's going to as a crowd. First, do a flood fill, so you know the base cost from each cell to the destination. Then start moving agents, following standard gradient descent. But as they occupy each cell, they should bump up its cost, and when they leave, bump it back down (and maybe update neighbors as well). This way other agents will notice high-density cells, because they suddenly have higher cost, and avoid them. But this can also lead to local minima (which might be okay).
  • Steering that incorporates A*. Make an A* path to the goal, and a "leash" that follows the path at a constant rate, pulling the agent with - but the agent also gets repelled by other agents nearby, and pulled in by the centroid of the group. As long as the leash is elastic, it can lead to pretty nice behavior.

On top of that, there's a question of formations. If you want to maintain a formation (e.g. 3x3 squad of soldiers), do A* for the centroid of the formation, and have each agent follow the path + offset for their position in the formation - eg. using the steering + path following technique above.

I don't think I have any papers ready as reference, but maybe I can dig up some...
Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #17 on: December 11, 2013, 10:28:15 AM »

Interesting methdos! Here's some flood-fill-like pathfinding from real life:





Actually that'd a cool element in a game! Like intelligent (Starcraft) creep  Corny Laugh
My premises for the pathfinding was
  • no pre-processing (like in A*) and
  • no collective data/intelligence among crowd members
Units only have limited (radius) vision to environment, other units, etc. Communication between units happens thru signals (now they can just ask other unit to move), and in this case, beacons.

It'd be great if different kind of units/enemies behave differently, not just look different. Maybe I experiment with some other type of crowd/swarm behavior too, as they look so fun! After all I'm trying to make a fun game here Smiley
Logged

meanwhale
Level 0
**



View Profile WWW
« Reply #18 on: March 03, 2015, 09:56:08 AM »

Hello! I started working on a new kind of a pathfinder, but ended up making a RPG/RTS game Smiley
It's based on that demo but currently pathfinding is maybe the worst part of its AI..... Will be fixed!
Give it a try:

http://stonewalldemo.appspot.com/

Longer post here:

http://forums.tigsource.com/index.php?topic=46663.0
Logged

Pages: [1]
Print
Jump to:  

Theme orange-lt created by panic