I am trying to make a flocking script, I have made a really basic one, but I'm not sure how to make the triangles follow each other. Has this got something to do with PVector? I have read about thins but don't fully understand it.
Does anyone know any good tutorials about it?
import toxi.geom.*;
//DECLARE
ArrayList agentCollection;
void setup() {
size (600,600);
smooth();
//INITIALISE
agentCollection=new ArrayList();
for(int i=0; i<100; i++) {
Vec3D origin= new Vec3D(random(width),random (200),0);
Agent myAgent= new Agent(origin);
agentCollection.add(myAgent);
}
}
void draw() {
background(0);
//CALL FUNCTIONALITY
for(int i=0; i< agentCollection.size(); i++) {
Agent mb =(Agent) agentCollection.get(i);
mb.run();
}
}
class Agent {
//GLOBAL VARIABLES
Vec3D loc = new Vec3D (0, 0, 0);
Vec3D speed = new Vec3D(random(-2,2), random(-2,2),0);
Hi I am playign around with the script below, btu I am trying to change the starting positions so they don't all start from the centre-----does anyone know how??? Thanks
int initBoidNum = 200; //amount of boids to start the program with
BoidList flock1,flock2;
void setup()
{
size(600,600,P2D);
//create and fill the list of boids
flock1 = new BoidList(initBoidNum,0);
//flock2 = new BoidList(100,255);
}
void draw()
{
//clear screen
background(205);
flock1.run();
//flock2.run();
//smooth();
//print framerate
//println(frameRate);
}
class Boid
{
//fields
PVector pos,vel,acc,ali,coh,sep; //pos, velocity, and acceleration in a vector datatype
float neighborhoodRadius; //radius in which it looks for fellow boids
float maxSpeed = 1; //maximum magnitude for the velocity vector
float maxSteerForce = .05; //maximum magnitude of the steering vector
float sMod,aMod,cMod; //modifiers for the three forces on the boid