Question

I have used face in NetLogo without any problems, but isn't towards just the same? (in the context of an agent facing towards the direction of a patch/agent)

towards

towards agent


Reports the heading from this agent to the given agent.

If wrapping is allowed by the topology and the wrapped distance (around the edges of the world) is shorter,     towards will use the wrapped path.

Note: asking for the heading from an agent to itself, or an agent on the same location, will cause a runtime error.

set heading towards turtle 1
;; same as "face turtle 1"
See also face.

Is there any scenario in which using set towards heading is better than using face?

Was it helpful?

Solution

Are there circumstances in which you would like to know the heading towards something without actually turning to face it? I'm sure you could think of many. One example situation would be choosing between two possible headings according to some criteria.

Let's say you want to face one of two agents, whichever one requires you to turn the least amount:

let first-heading towards first-agent
let second-heading towards second-agent

; compare my current heading to the two calculated headings:
let first-angle subtract-headings heading first-heading
let second-angle subtract-headings heading second-heading

if-else abs first-angle < abs second-angle
  [ rt first-angle ]
  [ rt second-angle ]

(In real life, you would probably do things a bit differently, but I hope this carries the point across.)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top