BehaviourComposer: ignore everything before this.
Begin description: Turn towards a given location. End description
Turn towards location
Begin NetLogo code:
substitute-text-area-for the-goal 5 5 substitute-text-area-for turn-expression desired-turn let desired-heading heading-towards the-goal let desired-turn desired-heading - my-heading turn-right turn-expression
End NetLogo code
The contents of the first text area represents a goal given as its x and y coordinate. You can replace it with two attributes or the results of some computations (e.g. a random distribution). You may want to introduce a maximum turning speed by replacing the second text area with
You can enhance this behaviour to repeatedly turn towards the goal.
This computes the angle from where the agent is to the x and y coordinates. The agent turns towards the goal by the difference between my desired-heading and my-heading. Note that turn-right does not immediately change my-heading but does so only at the end of the current cycle.
Repeatedly go forward in the direction of my heading can be used together with a repeating version of this to move towards a goal. Turn towards another turns towards another agent or a patch. There are many movement behaviours in the main library.Turn towards location was implemented by Ken Kahn
BehaviourComposer: ignore everything after this.