flocking sheep
Blitz3D Forums/Blitz3D Programming/flocking sheep
| ||
Hi all I need to create a flock of sheep who will graze, run as a herd and also run from the player and so, has anyone done any flock modelling? If so, any pointers? (or code?) |
| ||
A simple way is to do something like this: Set a number of 'weightings' for the sheep for the following vector distances: 1. Vector from sheep to player (negative) 2. Vector from sheep to nearest sheep (negative factor if too close, positive factor if too far) 3. Vector from sheep to nearest obstacle in front (negative) 4. Vector from sheep to nearest food Multiply each of these vectors by a factor, and then sum them to get a resulting 'direction' that the sheep should move in. The factors used don't need to be constant, for example the factor for point 3. above could be increased the closer the sheep is to the obstacle. That is a fairly simple way of doing it. |
| ||
Here's a little link where you can download binaries and code for examples of this type of behavior - http://www.wordware.com/files/ai/ It's not Blitz, but it's better than nothing. |
| ||
Also, google for BOIDS and you could adapt the example for sheep. Stevie |
| ||
Depending upon the complexity of what you want to achieve... a simple way to achieve this may be to use types for the sheep and use Supercam (found in the archives) on each to the previous object. I got six turtles to follow each other quite nicely using this method. Each following a lead entitiy but with varying distances. IPete2. |
| ||
Thanks for the suggestions. I checked out Boids and the code examples. In the end I've knocked up a fairly simple routine thus; A sheep can be eating grass (paused) if too long eating grass, set it to moving if moving get average direction of others in flock, turn towards that if too far away from init position, turn sheep around if moving for too long, set sheep to stop and eat grass if player too near take fright and move away from player if too far away from init position, turn sheep around the above doesn't give true flocking behaviour, but it's close enough. |
| ||
You know just because your sheep algorithm is giving you a bit of trouble, don't mean you need to swear at the poor things! :-) |
| ||
Well, now I have to design the little bastards. I'm thinking I'll take a leaf out of Pongo's cloud demo (blitz sprites with a nice cloud texture, offset/parented to a central pivot) for a nice volumetric effect. Because these are not real sheep. They're virtual sheep. |
| ||
"Flocking sheep" is illegal in New Zealand. :) |
| ||
Guess they must go in single file. :/ |
| ||
Do virtual sheep dream? |
| ||
How about flocking kangaroos? http://www.baetzler.de/humor/killer_kangaroo.html ... or how about a flesheating kangaroo http://www.lostkingdoms.com/snapshots/miocene_early_animals_roos.htm Andy |
| ||
Crikey! Thanks for the links. In the end I just did a simple algorythm whereby each sheep heads in the same general direction as the others for a short time. When stopped (grazing), it has a timer that depletes faster when other sheep are moving. When it runs out then that sheep moves again. As the sheep are within a small area, it gives the impression of a coherent flock well enough. |
| ||
LOL !! That kangaroo story is priceless!!! :D |