Setting a prey-predator relationship using Boids particles
By olivS, vendredi 28 décembre 2007 à 10:55 :: Blender tutorials :: #106 :: rss :: PDF
Using boids, it is easy to set animations with some prey/predator-like behaviour to some extend. In these cases, using Spherical Fieds emitters with negative Strength (repulsive, predators) or positive Strength (attractive, preys) will be quite easy and effective. Moreover, using the Die on Hit option (in the Extras panel) would prove useful also, when a predator successfully reaches a particle.
This tutorial is designed for Blender 2.50 and supplements Blender 2.50's release Logs about Boids particles systems. You need a SVN version of Blender to use it! Special thanks go to Janne Karhu for all the cool tips he provided me, both for the documentation and this tutorial.
Usage of Boids for a prey-predator simulation
Fichier(s) attaché(s) :
For Blender: 2.46 - Version française bientôt disponible(
)
Setting the scene
Start with a new scene ([ctrl]+[X]) and make sure the default cube is selected. In the Link and Materials panel of the Editing menu [F9], change its name in the OB: field to something more relevant, like: Prey. Move it somewhere else in your scene ([G] key in any viewport you prefer).
Then add a new Cube: [Space] > Add > Mesh > Cube. The same way as before, rename it something like: Predator and move it on the other side of your scene. Using the [S] key, give it a greater size than the prey cube (SixeX = SizeY = SizeZ = 5.0 for example).

Setting the particles systems
The Prey particles
Select the Prey cube. In the Object menu [F7], in the Particles buttons, click on the Add New button of the Particle System panel. Change a few of the values:
- Amount:
100in order to set a flock of 100 prey particles - Life:
1500in order to give each particle a lifetime enough for the prey-predatory simulation to work
Let now decide how the prey particles will appear: in the Visualization panel, make sure particle are shown like Point and give them a Draw Size of 3 (size of the particles in the 3D viewport). We want the Preys to be small, so in the Extras panel, set Size to 0.3 (actual size of the particle during the simulation; will help preys to keep near each other). Also, it's time to activate the Die on hit option, because we want these particles to disappear when they are reached by the Predator particles.
Now, we need to give the particles rules to follow. In the Physics panel, choose Boids in the dropdown menu as the particles system type, and adjust its Physics in order to make the preys a little slower than the predators (giving them some speed advantage over the preys) by lowering MaxVelocity to 7.000. It is not necessary to update any of the rules values, as we are trying to set a very simple simulation.

The Predator particles
Now, select the Predator cube. In the Object menu [F7], in the Particles buttons, click on the Add New button of the Particle System panel. Change a few of the values:
- Amount:
10in order to set a flock of 10 predator particles - Life:
1500in order to give each particle a lifetime enough for the prey-predatory simulation to work
To ease the understanding of the simulation, in the Visualization panel, select Cross instead of Point and give them a Draw Size of 10. As we want the predators to more easily "eat" the prey particles, set the particle Size to a greater value, like 1.5, which means that is a prey enters the predator particle radius, it is eaten. Because the prey particle is set to Die on hit, it then simply disappear.
And now, the most interesting part of this simulation: in the Physics panel, choose Boids in the dropdown menu as the particles system type, and adjust its Behaviour parameters as follow:
- Goal:
1.500in order to enhance goal seeking - Crowd:
1.00in order to enhance crowd avoidance - Collision:
0.500 - Avoid:
0.500 - All other:
0.100-0.250
and move the Goal and Crowd priorities upward in the list of rules using the little up and down arrows in front of each rule.
Predators are especially efficient in hunting. To reflect that, make sure that MaxVelocity (by default 10.000) is higher than the prey's (7.000 if you followed the tutorial) and set a higher AvVelocity too (for example, 0.500 vs 0.300 for the preys). Also, still to give predators some advantages over the preys, give them a better TangAcc (for example, 0.500 vs 0.200 for the preys). Finally, decrease the flock size to something like N 3 so that the predators become able to hunt in small groups.

Setting the fields: how do they really work?
Now we are almost done. Select the Prey cube emitter and in the Physics buttons, in the Fields panel, choose PSys instead of Object and set a Spherical field for it with a positive Strength of 2.000. Then select the Predator cube emitter and, also in the Fields panel, choose PSys.001 instead of Object, and set a Spherical field with a negative Strength of -10.000 and a Fall-off of 2.000.
Basically, the positive value will tell to all other boids particles of the scene that these particles are preys which predators would find apetizing and try to catch because of their 2.000 weight. With the same idea, the negative value will inform all other boids that those particles are very dangerous predators because of a weight value of -10.000 and that any prey particles in the vicinity should really try to avoid them very hard!
The Fall-off works exactly like the fall-off from classical fields. For example, when a predator is far away, the prey particle will almost not notice it, because the fall-off makes the field too weak beyond a given distance. The closer the predator gets, the stronger the field effect will become, increasing the urge of the prey to flee away from the predator once it has become closer. The max distance setting can also be very usefull here, because thanks to it, a predator can get really close to its prey without being detected until the max distance is reached and the prey "alarm" is triggered.
Playing the simulation
The only thing else you have to do is to set the simulation length. This mostly can be done in the Anim tab of the Render buttons, in the Scene menu [F10]: you just have to set the End button to a greater value, like 1000-1500, according to the Life duration of the particles and a few try-and-guess simulations. If you need to adjust the particles Life duration, then Clear the cache beforehand in the Particles System panel. When you are ready to play the simulation, just do a [ALT]+[A] with the mouse cursor in the viewport of your choice, and use [ESC] to put the simulation to an end.








Comments
1. On samedi 5 janvier 2008 à 13:34, by Rookie
2. On samedi 5 janvier 2008 à 15:37, by joe
Réponse de olivS le samedi 5 janvier 2008 à 17:49
3. On dimanche 6 janvier 2008 à 07:33, by neobloodline
4. On lundi 7 janvier 2008 à 04:43, by Ammusionist
5. On mardi 1 avril 2008 à 06:49, by G405
Réponse de olivS le mardi 22 avril 2008 à 21:34
6. On samedi 31 mai 2008 à 10:28, by Ape
7. On lundi 9 juin 2008 à 03:46, by alloy007
8. On mardi 10 juin 2008 à 18:35, by Ben
9. On vendredi 20 juin 2008 à 19:41, by anv
10. On jeudi 26 juin 2008 à 17:00, by dp
11. On vendredi 27 juin 2008 à 09:11, by dp
12. On vendredi 19 septembre 2008 à 22:22, by bol
Add a comment