Pregunta

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.

¿Fue útil?

Solución

The facexy primitive will allow you to set your turtle's heading toward the origin:

http://ccl.northwestern.edu/netlogo/docs/dictionary.html#facexy

Otros consejos

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.

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.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top