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-turnlet desired-heading heading-towards the-goallet desired-turn desired-heading - my-headingturn-right turn-expression End NetLogo code VariantsThe 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. How this worksThis 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-behavioursRepeatedly 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. HistoryTurn towards location was implemented by Ken KahnBehaviourComposer: ignore everything after this. |