Libraries‎ > ‎Library‎ > ‎Movement‎ > ‎

Turn towards location

BehaviourComposer: ignore everything before this.

Begin micro-behaviour:
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

Variants

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 within-range (canonical-heading desired-turn) -30 30 (this ensures that the angle turned is between -30 and 30).

You can enhance this behaviour to repeatedly turn towards the goal.

How this works

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.

Related micro-behaviours

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.

History

Turn towards location was implemented by Ken Kahn
BehaviourComposer: ignore everything after this.
Comments