I created a turtle in NetLogo which is moving randomly and there are some obstacles. Is it possible to get its current direction? I want to get the turtle to walk back to the center when it sees an obstacle. I can calculate distance to the center, but since I don't know its direction I can't say forward or backwards, for example.
Asked
Active
Viewed 1,735 times
3 Answers
5
The turtle's current direction is given by the heading
variable. You can both read and write to this variable in order to change the turtle's heading. You can also change it using facexy
as N. Payette mentioned.

Jose M Vidal
- 8,816
- 6
- 43
- 48
3
The facexy
primitive will allow you to set your turtle's heading toward the origin:
http://ccl.northwestern.edu/netlogo/docs/dictionary.html#facexy

Nicolas Payette
- 14,847
- 1
- 27
- 37
-
Thank you for the answer.I understood facexy.But now i am trying to put obstacle in front of the turtle while it is going to the origin.Namely when it see the obstacle ,turtle will put the obstacle in front of it to carry until the origin.To make this , every time I am checking whether the coordinates of turtle are positive or negative(to always put obstacle in front of it not back or other side).Do you have any idea to make it more simple or cleverer?? – Ecrin Jan 31 '12 at 23:04
-
If I correctly understand what you mean, what you need is `patch-ahead`: http://ccl.northwestern.edu/netlogo/docs/dictionary.html#patch-ahead – Nicolas Payette Jan 31 '12 at 23:57
0
ask turtle <who>
[If (patch-ahead = obstacle)
[
facexy origin
fd distance origin
]
]
Here obstacle and origin are the respective patches. Building on what Jose M Vidal and N. Payette have already said.

Abhishek Bhatia
- 9,404
- 26
- 87
- 142