flocking behaviour in GS?
I asked this last March and no one replied. Now I am playing with it again. Has anyone tried this and got decent results? Be very glad to hear of your approach or thoughts on the matter. My early attempts were pretty rubbish but things seem to be starting to work, but not well. I don't think I'm going about the logic quite correctly.
thanks kipper
thanks kipper
Comments
For the break behavior you can have an attribute.
Have when touch is pressed:
change attribute to true
timer after 1 second(or however long you want) run to completion checked, change attribute to false
Then you can put a rule in the flocking actors when that attribute is true, change velocity in a random direction and speed, so they scatter.
Also for the accelerate toward rule based on magnitude i mentioned above, have that in a rule when attribute is false. So that accerlate towards doesnt effect the scatter, and when the scatters over they flock back together.
Maybe thatll help get you started
cheers
I do wonder if this is the right approach, and think I might be better looking at nearest neighbour and building the behaviour around that, with a moderator that draws the group in, and then have each actor check the distance from nearest neighbour to avoid collision (with possibly a second nearest to generate a vector to angle to generate a repulse angle).
all thoughts welcome.
Ive made this template for ya , its a herd movement :
http://www.mediafire.com/?q1fxfj1jjwauzf8
Cheers
Roy.
Guru Video Channel | Lost Oasis Games | FRYING BACON STUDIOS
"Ive made this template for ya , its a herd movement "
Reminds me of Justin Bieber.
"Maybe this will help..."
Funnily enough I was listening to that only yesterday !
Justin Bieber?!? am i missing something ?!
Roy.
http://www.mediafire.com/?g1qvc7ddhw0cvv8
Roy.
"Justin Bieber?!? am i missing something ?!"
Click > http://www.mediafire.com/?4vbcw5pciivbeyj
(no offense to justin of course )
Roy.
What do you think I have been working on for the last 2 years from my high security iOS developers lair, AngryBieberSwarmManor-HD(Retina)™.
In general each actor needs three simple (hah!) rules/behaviors:
1) move each actor towards what it perceives is the center of the flock
2) move each actor away from any other actor that it perceives it is getting too close
3) move each actor in the same general direction as it perceives of all (most) of the other actors' direction
there might be fourth rule:
4) try to match the perceived average speed of all the other actors
Hope this helps!
RThurman
on your points.
1). I am doing that with an average of the x and y to determine the centre of the flock
2). (and this is where I am not 'done') As I understand from reading a bit and taking from what I understand, each actor has to be aware of the relative position of each other actor. This I have read can actually not be the case if you sector the play field and have each actor check for actors in their current field and adjacent fields so you can reduce the processing. The weighting of the repulsion direction should be based on proximity to those within those fields.
3). (I am not even close) I guess there needs to be a flow direction but is this weighed for the perspective of the individual actor or does a general average work not work for all?
4). Again is it an inclusive average of speed or exclusive of the perceiving actor?
I can see a lot of constrains going on here but wonder if with the speed were not too high and with enough distance apart one could in fact run the processing with timers offset in each of the actors for placing positions in attributes and altering directions, etc? Of course one could perceive that this is happen at the mighty 60fps, but how low might one go before it all falls apart. My guess is it about testing and build a system which can be trimmed in real time. I shall hopefully have this done by the end of next week(joke) or possibly by the time I am 90.
cheers Kipper
1) How are you averaging the x,y coordinates to obtain the flock center? I couldn't imagine how to do this easily without arrays. (Well, one could brute force it by adding each individual actor's x coordinate in one long monster equation.) Am I missing something simple here?
2) How about using a collide test against each actor? (Kind of the way P-O-M's demo does.) If you had each actor with a relatively large transparent area around it -- using collide might be able to give an actor a quick proximity check. (If it collides with another actor -- move it slightly away from vectorToAngle between the two.)
3) If you are already getting average x or y (for #1 above), can't you get the average Rotation of all actors -- using a similar method?
4) Same with #1 and #3. This would be the velocity (x and y) of each of the actors -- all averaged together.
In general it would be more correct to have each actor have its own unique perception of the average(s). But a workable approximation would be to have general calculations of flock center, mean flock direction, and mean flock speed.
I am very curious about how you are obtaining the average x and y coordinates to determine the flock center. That seems (to me) to be a key calculation. If it can be done efficiently (without slowing GS to a crawl), that would be great!
I would suggest not using constrains. They try to calculate everything as fast as possible. The flock simulation does not need instantaneous updates. I'd suggest using a timer set at .025 seconds at the fastest.
Hope this helps!
RThurman
In some ways I think I am only just getting going on this, but I have built a basic system to drastically improve on. It's mostly family duties over the next few days but I'll post more. My next goals are the refinement of point 2 and moving onto point 3 and 4. I've to go back and play with timers for the placement of self x y and build a more tweakable system with references to values in my control/summing actor or a slider system on screen. I'll do a demo soon. Given my previous attempts at this (that didn't get this far) I am hopeful.
Cheers Kipper and the kiplets
While you might consider what you have as "primitive" it is exactly how the big gun developers do flocking. The thing to remember is that animal behavior is very primitive. Just a few simple rules. It is the combination of four (three really) simple rules of animal behavior that give rise to the emergent property of flocking.
You have discovered that points 1 and 2 give rise to "shoaling" as an emergent property of fish group behavior. When you get point 3 working you will have "schooling". I think point 4 will happen as an emergent property of the other three, under certain conditions.
GameSalad is an amazing tool. It can easily handle simulations of group behavior/dynamics. But it will be even easier to do this when arrays (read/write tables), joints, and robust collision detection are available.
Please keep us updated. This is interesting stuff!
RThurman
latest... got distracted with what I can do with whats in place.... Maybe a good thing to understand the scope of it, before moving on. Thanks @thurman for the comments. I am taking in all I can at one go and still pondering the next stage and clean up of this one. SHoaling it is with a bit of primitive (in my sense) mucking about with. Very much enjoying it.... more soon...
RThurman
p.s. Love the art style!
So if you were looking to recreate that effect perhaps when you identify they are in alignment, you could shift their common direction and speed for an instance and use a few actors to get out of synch and utilize the logic you have to get them back in line? I'd imagine that flocking would be close but not quite as 'magically organized or instantaneous' with sheep or non-fish .... perhaps QS could let us know how they do it