BehaviourComposer: ignore everything before this.
Begin micro-behaviour:
Begin description: Compute the heading needed to turn away from other agents. End description
Turn away from others
Begin NetLogo code:
substitute-text-area-for expression-for-others other all-individuals substitute-text-area-for cycle-duration 1 substitute-text-area-for weight-expression 1 do-every cycle-duration [let weight weight-expression ask expression-for-others [ask myself [set my-desired-headings my-desired-headings + weight * canonical-heading heading-towards-another myself + 180 set my-desired-headings-count my-desired-headings-count + weight]]]
End NetLogo code
This updates my-desired-headings by adding the headings towards each of the others plus 180 degrees (i.e. away from the others). You can replace it an expression such as all-of-kind "Prototype1". Or if you wish to limit this to only those within 3 units use (all-of-kind "Prototype1") in-radius 3.
You can change the weight expression if you want this to count more or less than other micro-behaviours that update my-desired-headings.
This updates my-desired-headings by adding all the headings to the others. It adds 180 to point away. my-desired-headings/my-desired-headings-count computes the average desired heading. canonical-heading ensures that equivalent headings (e.g. -30 and 330) are treated the same.
Turn toward the desired-direction computed by other behaviours is need to actually turn the agent in the direction computed by this micro-behaviour.
Compute the heading needed to turn towards other agents. can be used to follow rather than avoid other agents.
Turn away from others was implemented by Ken Kahn on 13 August 2010.
BehaviourComposer: ignore everything after this.