Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 7 additions & 8 deletions chp06_agents/box2d/Flocking_box2d/Boid.pde
Original file line number Diff line number Diff line change
Expand Up @@ -47,17 +47,17 @@ class Boid {
ali.mulLocal(1);
coh.mulLocal(1);
// Add the force vectors to acceleration
Vec2 loc = body.getWorldCenter();
body.applyForce(sep,loc);
body.applyForce(ali,loc);
body.applyForce(coh,loc);
Vec2 pos = body.getWorldCenter();
body.applyForce(sep,pos);
body.applyForce(ali,pos);
body.applyForce(coh,pos);
}

// A method that calculates and applies a steering force towards a target
// STEER = DESIRED MINUS VELOCITY
Vec2 seek(Vec2 target) {
Vec2 loc = body.getWorldCenter();
Vec2 desired = target.sub(loc); // A vector pointing from the position to the target
Vec2 pos = body.getWorldCenter();
Vec2 desired = target.sub(pos); // A vector pointing from the position to the target

// If the magnitude of desired equals 0, skip out of here
// (We could optimize this to check if x and y are 0 to avoid mag() square root
Expand Down Expand Up @@ -102,7 +102,7 @@ class Boid {

// Wraparound
void borders() {
Vec2 loc = box2d.getBodyPixelCoord(body);
Vec2 pos = box2d.getBodyPixelCoord(body);
Vec2 vel = body.getLinearVelocity();
float a = body.getAngularVelocity();
if (pos.x < -w) {
Expand Down Expand Up @@ -254,4 +254,3 @@ class Boid {


}