0

I am trying to make that when an agent is less than a specified distance from any other, they change color. But when I use getNearestAgent(this.getPopulation()) it gives me the Agent in the position 0 of the population list. I'm using an event to make the agents change color. this is the code of the event and the output of the console

and the color change depends of the rate of the event and sometimes the distance from the point (0,0,0)

NicolasA13
  • 15
  • 3

1 Answers1

0

You can use the distanceTo() function.

Each agent will need to loop through all the other agents and then check their distance to the other agents.

enter image description here

Jaco-Ben Vosloo
  • 3,770
  • 2
  • 16
  • 33
  • I was working on this problem and it turns out that I made a mistake when setting the rate and in my simulation it looked for the nearest agent once every 100 seconds so it always returned agent [0] as the nearest one – NicolasA13 Aug 24 '21 at 19:09