face
makes a turtle change its heading to point towards a specific patch or another turtle. For example, ask turtles [ face patch 0 0 ]
turns all turtles in a model to face the center of the model.
In the model example below, we have a person and a butterfly. The person is trying to catch the butterfly, while the butterfly is trying to run away from the person. We use the face
primitive to make the person turn to the butterfly at every tick before moving one step closer to the butterfly. We also use the face
primitive to make the butterfly turn to the opposite direction by making it look at the person first and then turn 180 degrees (and add a bit of randomness to simulate the flight of the butterfly) at each tick before moving 1 step forward.
xxxxxxxxxx
breed [butterflies butterfly]
breed [people person]
to setup
clear-all
create-people 1 [
set shape "person"
move-to one-of patches
]
create-butterflies 1 [
set shape "butterfly"
move-to one-of patches
]
reset-ticks
end
to go
ask people [
if any? butterflies-here [ stop ]
face one-of butterflies
forward 0.5
]
ask butterflies [
if any? people-here [ stop ]
face one-of people
rt 180 + random 90 - random 90
forward 0.5
]
tick
end
Once you mastered the face
primitive, don't stop there. Check out the resources below to improve your NetLogo skills.
face
primitive: