[Behaviour] Boids Flocking

Post your completed addons to share with the community

Post » Sat Jan 12, 2013 4:21 pm

(Disclaimer - I've only been working with Construct2 since Monday, so I have no idea if this follows best practices or not, but it seems to work for my purposes so I thought I'd share it here!)

This adds a new movement behaviour based on the "Boids" flocking model first described by Craig Reynolds at http://www.cs.toronto.edu/~dt/siggraph97-course/cwr87/

When flocking, a character's movement is based not only on its desire to reach a target, but upon the relative position and speed of other members of its flock. There are four factors that influence the direction of movement - the desire to:
- Head towards a target position
- Avoid collisions with immediate neighbours
- Head in the same direction as the rest of the flock
- Stay close to the centre of the flock

I had tried originally to implement this behaviour using the "Custom Movement" behaviour, but it seemed to involve a lot of hacking on the event sheet (explored by R0j0hound in http://www.scirra.com/forum/boids-tests_topic59833.html), so wrapping it in a new behaviour seemed more appropriate.

Using the attached "boids" behaviour, you can set the target X,Y and also specify an object type to which an instance will flock together. The relative influence of each factor on the final direction of movement is governed by the targetPriority, seperationPriority, alignmentPriority, and cohesivePriority parameters. The seperationDistance parameter controls the optimum distance which each boid tries to maintain from others in the flock.



Behaviour is http://www.a3uk.com/boids/boids_behaviour.zip, and example CAPX is http://www.a3uk.com/boids/Boids.capx. The example (which obviously requires the behaviour to be installed) shows 10 bat sprites that will follow the mouse cursor around the screen. You should notice that the movement of each individual bat is affected by the behaviour of other bats in the flock and, while they aim towards the cursor, they should also steer to avoid collisions (seperation), and try to remain together (cohesion).



Comments/suggestions welcome.

[p.s. I must congratulate the Construct2 designers for creating such an elegant plugin system - it was refreshingly simple to use!]tanoshimi2013-01-12 16:24:07
B
8
S
2
G
3
Posts: 83
Reputation: 2,668

Post » Sat Jan 12, 2013 5:04 pm

Wow. Very cool.
ImageImageImage
B
67
S
19
G
121
Posts: 3,200
Reputation: 72,887

Post » Sat Jan 12, 2013 5:14 pm

Great plugin. we get very few game play plugins and its refreshing to see something useful. This will diffidently get used in my projects. Thanks and hope you continue doing game play related plugins! 8)
B
50
S
11
G
7
Posts: 274
Reputation: 8,146

Post » Sat Jan 12, 2013 7:43 pm

Looks good, fps is solid 60.
One thing, the action allows you to select other objects.
I don't see the purpose here as a behavior would automatically be applied to all instances only.

Other than that its a great implementation.newt2013-01-12 19:44:22
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Sat Jan 12, 2013 9:46 pm

Thanks all for the feedback.

@Newt - I think I had originally planned to make it possible to flock with instances of other types of object but, as you point out, it probably makes more sense to just flock all instances of the same type of object on which the behaviour is added.
B
8
S
2
G
3
Posts: 83
Reputation: 2,668

Post » Sat Jan 12, 2013 11:57 pm

Very interesting! Good for npc AI.
B
97
S
22
G
176
Posts: 4,109
Reputation: 103,021

Post » Sat Feb 09, 2013 6:31 pm

This is great! Thank you @tanoshimi I just requested this in another thread as a suggestion for Construct 2 updates. it is on page 2 if you are interested :)
http://www.scirra.com/forum/topic62646_post387830.html#387830

I describe an "alpha" system for promotion.

The system was very useful for situations where they wanted troops to follow the next in command, or if they wanted the Strongest, or the boid with the most health to seem to take the lead as the alpha.

Please excuse me if you have already added something like that.

I am looking forward to getting off work, and trying this in my spare time 8)

Thanks again tanoshimi :)

Edit:

A way to choose 2 or more animations to randomize would be really neat too. That way they would not all be walking exactly the same way, some can have a limp, some can have injuries, or a change in armor, or clothes. That would all be possible with some sort of animation randomize-er. I understand it would be really easy to just do this with the current on create block+object set animation random (X,Z) . I am just suggesting it to streamline production usage :)
jojoe2013-02-09 18:44:25
B
28
S
8
G
4
Posts: 767
Reputation: 5,940

Post » Mon Feb 25, 2013 10:41 pm

This is awesome! Thanks.
B
11
S
3
G
3
Posts: 19
Reputation: 2,942

Post » Thu Apr 04, 2013 7:43 pm

Any chance of some updates like setting max speed at run time, and an activated setting?
Image Image
B
161
S
48
G
90
Posts: 7,347
Reputation: 66,749

Post » Thu Apr 04, 2013 8:17 pm

It sounds awesome but I am forbidden?

Best Regards;
B
16
S
4
G
1
Posts: 332
Reputation: 3,016

Next

Return to Completed Addons

Who is online

Users browsing this forum: dark1994 and 2 guests