Search code examples
netlogoflock

How to flock turtles within vision distance and heading degrees?


I set a vision parameter in the interface as a slide, suppose vision was set as 5. Now, I want to set turtles flocking behavior within the vision distance, but also taking into account of within less than 90 degrees of turtle's heading.

The behavior is in the find-flockmates, I copy the codes as below:

to find-flockmates  ;; turtle procedure
  set flockmates other turtles in-radius vision   ; flockmates within vision radius distance


end

My thought is to add another set, for turtle to rt first, and less than 90 degree, but I am kind of confusing how to sort out flockmates within this degree.


Solution

  • Check out the in-cone primitive. It may do what you want.

    https://ccl.northwestern.edu/netlogo/docs/dictionary.html#in-cone

    Note that the cone is centered on the direction the turtle is currently facing, so if you ask the turtle

    right 45
    let flock turtles in-cone vision 90
    left 45
    

    your will get those turtles in that 90 degree right cone.