Coding Assignment Week #8

CONCEPT

For this week’s sketch, I wanted to explore the different autonomous behaviours we have covered in class and how they interact and respond to each other. In other words, what if instead of studying each steering method separately, we create a system where every object has its own steering behaviour and we how it affects and influences other vehicles having a different behaviour. With this idea, I started to experiment!

PROCESS

    1. Multiple wandering objects:
    2. Then I decided to have smaller objects to either pursue, evade, or arrive at one of these big wandering (blue) objects.
    3. Currently, in the above sketch, each smaller target is currently pursuing or evading a fixed predefined wanderer. I wanted to try to randomize that based on whichever wanderer is closest. I modified the code to calculate the minimum distance and store it and use that to assign the target. I made a line between the wanderer and pursuer / evader for increased visibility.
      Here is the code for it:

      let steering = [];
      
      // to calculate and find min distance between current seeker 0 and all wanders
      let d = p5.Vector.dist(vehicle_seekers[0].position, vehicle_wanderers[0].position); // to store the min distance - initially start with first available dist
      let index = 0; // to store which wanderer is closest
      for (j = 1; j < N1; j++) {
        let d2 = p5.Vector.dist(vehicle_seekers[0].position, vehicle_wanderers[j].position);
        if (d2 < d) {
          d = d2;
        }
      }
      
      steering[0] = vehicle_seekers[0].pursue(vehicle_wanderers[index]);
      
      // making a line between them for more visibility
      push();
      stroke(2,255,2);
      line(vehicle_seekers[0].position.x, vehicle_seekers[0].position.y, vehicle_wanderers[index].position.x, vehicle_wanderers[index].position.y);
      pop();
    4. Some improvisation. Firstly, I added more wanderers for the system to be more dynamic. Secondly, the pursuer gets suck to the target once it seeks it (i.e. reaches it). So, I tried the opposite. Instead of pursuing the closest target, pursue the farthest. So, it keeps changing its direction and does not get stuck.

      The code for it changed as described below:

      let steering = [];
      
      // to calculate and find max distance between current seeker 0 and all wanders
      let d = p5.Vector.dist(vehicle_seekers[0].position, vehicle_wanderers[0].position); // to store the max distance - initially start with first available dist
      let index = 0; // to store which wanderer is closest
      for (j = 1; j < N1; j++) {
        let d2 = p5.Vector.dist(vehicle_seekers[0].position, vehicle_wanderers[j].position);
        if (d2 > d) {
          d = d2;
        }
      }
      
      steering[0] = vehicle_seekers[0].pursue(vehicle_wanderers[index]);
      
      // making a line between them for more visibility
      push();
      stroke(2,255,2);
      line(vehicle_seekers[0].position.x, vehicle_seekers[0].position.y, vehicle_wanderers[index].position.x, vehicle_wanderers[index].position.y);
      pop();
    5. Lastly, I created my own trailing path with these new set of rules for steering behaviour to create the below output!

Pretty Mishap?

So, while on my way to figuring out the code for trailing paths, I kind of ran into this happy accident. The trails clearly do not appear as they should but it was interesting enough to document. I believe this is because I am not correctly popping from the list of paths and rotating indefinitely.

I then fixed the rotating problem but ran into something the professor warned us about – edge to edge lines!! (when the object wraps around, it draws a line across the page). I do like this effect too – seems like a women quilt / blanket.

It was easy to fix this as I did this modification for the pen plotter too in my midterm. Plotting dots was easy, but for plotting lines, I had to reset the line every time it made a huge jump so as to not have lines all across the page. This one was not exactly the same, but similar in terms of the concept.

FURTHER DEVELOPMENT

Currently my design is based on wanderers being the main targets. One way to improve this is by having different agents (objects) each having their own property of wandering, pursuing, evading etc., and calculating the minimum distance from each of those, not just the wanderers. This way, an evader could flee a pursuer closest to them, or a pursuer could seek a target farthest to them (not closest). That would be interesting to see.

Leave a Reply

Your email address will not be published. Required fields are marked *