# Feedback Loops /// 2d Boids Implementation

Hi, I’m in the process of implementing a swarm algorithm and I am having difficulty getting my feedback loop to work…

The way my patch works is that :

1. random initial positions are passed to a 2d vector node
2. the position vectors are then fed to several different rules which are summed back in.
3. The output of this summing node is fed simultaneously to the renderer and back to the original vector node through a frame delay node…

The problem I am having is that the effect of the rules now just send the boids flying immediately off the screen! I am guessing this is a result of the feedback loop counting up towards infinity… How does one deal with this?

I tried multiplying the feedback by a factor < 1, but of course the boids all just ended up in the centre of the page!

I can upload my patch if you need to see it but its a bit of a mess :)

Any help would be much appreciated, I am tearing my hair out here!

clean the patch and upload it, there must be an error in there ;)

Ok here you go! Its a bit hard to follow maybe… Its my first patch so more than likely some rookie error.

I have all the rules turned off at the moment, you can see the tabs to switch em on… I used attractors for maintain min distance apart and to keep boids together based on average position too…

edit : I have a feeling it could be to do with the attractors… Kind of functions with those rules turned off but looks jumpy…

swarm3.v4p (72.0 kB)

hi si, you can have a look at this patch, epecially the ‘dt’ factor could help you.

here a few hints:

you should make subpatches (ctrl+shift+n), for the rules, with a defined interface for the in and outputs.

using the absolute value for the average velocity looks wrong, as all forces are directed, this will always result in an average force in the upper righ direction.

dont know why, but in vvvv polar and cartesian are not exectly the inverse of each other. in 2d you should use points2vector and vector2points.

but all together, it looks good, almost there…

Thanks a lot for the help tonfilm! Still getting my head around how vvvv works… :)

Yeah I found playing around with the ‘force’ values for each rule kept stuff on the screen… Think that has a similar effect to the dt factor there?

Subpatches?! Cool! That’ll help tidy stuff up, thanks!

I’ll bring the sign part back into the equation for average velocity so…

Thanks again!

Sorry tonfilm, just a quick question…

Those vector2points & points2vector nodes have 4 inputs? Even if I put 0,0 in for x2,y2, there are still non-zero values outputted? That was why I was using the polar and cartesian nodes…

ah yes, i see what you mean. i remember this thread, where the same was neede for complex numbers, which are just 2d vectors…