130 likes | 367 Vues
Group Behavior. CIS 487/587 Bruce R. Maxim UM-Dearborn. Flocking. Emergent behavior that appears complex and purposeful, but is really derived from simple rules followed blindly by the agents Composed out of three group behaviors Cohesion (steering toward neighbors’ center of mass)
E N D
Group Behavior CIS 487/587 Bruce R. Maxim UM-Dearborn
Flocking • Emergent behavior that appears complex and purposeful, but is really derived from simple rules followed blindly by the agents • Composed out of three group behaviors • Cohesion (steering toward neighbors’ center of mass) • Separation (creates force that steers away from neighbors) • Alignment (keeps agent heading in the same direction as neighbors)
Combining Steering Behavior • In an FPS you might want a bot that combines path following, separation, and wall avoidance • In an RTS you might want a group of bots to flock together while wandering, avoiding obstacles, and evading enemies
Slides based on theCode from Advanced 3DGame Programmingby Kenneth Finney
Group Behavior Rules • Members of a group should not bump into one another (collision avoidance) • Each group member should try to maintain its position relative to the center of the group (swarm centering) • Each member of the group should attempt to match its velocity with the average velocity of the other members (velocity matching)
AIDropPoints • Execute the fps.starter demo and open the World Creator Interface • On lower right side, drill down and click on MissionObjects/System/SimGroup • Call the object AIDropPoints and switch to the World Editor Inspector (F3) • Make AIDropPoints an instant group using the Alt key and left mouse button
Swarm • Switch to the World Creator (F4) • On lower right side, drill down and click on MissionObjects/System/SimGroup • Call the object Swarm and switch to the World Editor Inspector (F3) • Make Swarm an instant group using the Alt key and left mouse button
SpawnSphere - 1 • Exit the Mission Editor (F11) and enter camera fly mode (F8) • Find a good location for an swarm and place it 20 feet off the terrain • Switch back to the Mission Editor (F11) and enter World Creator (F4) • Drill down to Shapes/Misc on lower right and click on SpawnSphereMarker • Place at least two more in the world
SpawnSphere - 2 • Switch to World Editor Inspector (F3) • Select all 3 SpawnSpheres in upper left (Ctrl and left mouse click) • Click on expand all • Changes the radius field to 10 and press Apply button • Save the mission and exit to the desktop
Code Modifications • Add this line to the server\script\game.cs function onServerCreated and disable the aiGuard code exec(“./swarm.cs”); // exec(“./aiGuard.cs”); • At the end of the same game.cs file add this line to start the bot placement process Schedule(3000, 0, “CreateBots”); • Save game.cs and copy the file swarm.cs to the server\script folder
Test Swarm • Run the test application again. • Open the console and type InitSwarm( ); • To add some more bots to the swarm type SpawnASwarm( ); • Close the console window and watch them go
Chasing Swarm • Replace the SwarmBotDB::DoScan function in the file swarm.cs • Add the code for functions AIPlayer::FindLeader AIPLayer::GetClosestHuman • Save the file and get ready to test the new behavior
Test Chasing Swarm • Run the test application again. • Open the console and type InitSwarm( ); • To add some more bots to the swarm type SpawnASwarm( ); • Close the console window and watch them go • See how close (or far away) to get swarm to chase the player avatar