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 › circumnavication
Page Index Toggle Pages: 1
circumnavication (Read 764 times)
circumnavication
May 2nd, 2010, 10:45pm
 
       I am working on a sketch in which an animated object seek another animated one. What I would like to have happen is have the first object approach the second one, then if the distance is too close, move around behind it and then once behind it, move closer to it. I can nearly do this but very primitively.
      The avoidance path of what I have right now is very choppy and not all the smooth circular path that I would like it to be. Does anyone have a hint as to how I might go about this? I would like the movement to be the same no matter the approach angle of the first object. Here is what I have: Code:


if(dist(x,y,X_,Y_) < 150){
         if(x < X_&& y < Y_- 50){
           x = x - 10;
           y = y - 10;
         }
         if(x > X_&& y < Y_- 50){
           x = x + 10;
           y = y - 10;
         }
         if(y > Y_- 50 && x < X_){
           y = y + 10;
           x = x + 10
         }
         if(y < Y_- 50 && x > X_){
           y = y + 10;
           x = x - 10;
         }
       }

Re: circumnavication
Reply #1 - May 2nd, 2010, 11:13pm
 
I say this time and time again... if you want help, please post a block of code that us helpful people can copy, paste, and run, to see what you've got so far. As it is now, if I want to test your code, I'd have to write code to define two objects, then make one move, then make the other try to follow it using your code... etc...

It's a hassle! Post the whole thing.
Re: circumnavication
Reply #2 - May 3rd, 2010, 1:35am
 
Fasces wrote on May 2nd, 2010, 10:45pm:
not all the smooth circular path that I would like it to be.

Might need some trigonometry maths, there...
Page Index Toggle Pages: 1