Libraries‎ > ‎Library‎ > ‎Interact with others‎ > ‎

Turn-in-desired-direction

BehaviourComposer: ignore everything before this.
Begin micro-behaviour:
Begin description:
Turn toward the desired-direction computed by other behaviours.
End description

Turn in desired direction

Begin NetLogo code:
substitute-text-area-for cycle-duration 1
substitute-text-area-for columns: 71 maximum-angle 30
do-every cycle-duration 
   [if my-desired-headings-count = 0 [stop]
    let maximum-turn 
        maximum-angle
    let desired-heading my-desired-headings / my-desired-headings-count
    let desired-turn canonical-heading (desired-heading - my-heading)
    set my-next-heading my-next-heading +
                        within-range desired-turn
                                     (- maximum-turn)
                                     maximum-turn
    set my-desired-headings 0
    set my-desired-headings-count 0]
End NetLogo code

Variants

You can change the expression that computes the maximum amount that I turn on each cycle.

How this works

This uses the desired heading computed by other behaviours to determine how much it should turn in order to face in the desired direction. A maximum amount of turning per cycle is enforced by the call to within-range.

Related micro-behaviours

turn towards others and turn away from others compute my-desired-headings.

History

Turn in desired direction was implemented by Ken Kahn on 13 August 2010.

BehaviourComposer: ignore everything after this.
Comments