We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
IndexProgramming Questions & HelpPrograms › Boid constraints
Page Index Toggle Pages: 1
Boid constraints (Read 777 times)
Boid constraints
Dec 7th, 2009, 11:57am
 
Just curious if anyone out there knows a good way to constrain the "flock" model of boids to a user-defined rectangular area, such that they change vector when they hit the edge. Any help would be greatly appreciated. Smiley
Re: Boid constraints
Reply #1 - Dec 7th, 2009, 3:59pm
 
Am I being stupid or do you just need:

http://processing.org/learning/topics/bounce.html
Re: Boid constraints
Reply #2 - Dec 7th, 2009, 4:08pm
 
I would say if he is working with vectors he probably got a velocity vector. so all he needs to do is to multiply it by -1... But thats more or less what you just said.

so it could look something like this :


void bounceOfEdge(){
   if (pos.x > width || pos.x < 0){ // if x pos is greater than right hand edge OR less than left hand edge
     vel.set(vel.x*-1,vel.y,0); // bounce off the edge by turning vel. negative
   }
   if (pos.y > height || pos.y < 0) { // if y pos is greater than bottom edge OR less than top edge
     vel.set(vel.x,vel.y*-1,0);
   }
Re: Boid constraints
Reply #3 - Dec 8th, 2009, 1:13am
 
Cedric wrote on Dec 7th, 2009, 4:08pm:
I would say if he is working with vectors he probably got a velocity vector. so all he needs to do is to multiply it by -1... But thats more or less what you just said.


Indeed - I was trying to think of some reason why it might not be a simple case of RTFM...
Page Index Toggle Pages: 1