forward
is a turtle primitive that makes the asked turtle move forward on a straight patch for a provided number of units. The shorthand version of this primitive is fd
.
ask turtles [
forward 2
]
ask turtle 0 [
fd 3.35
]
Things to keep in mind when using forward
:
ask turtles [ forward speed]
.forward
primitive. right
or left
primitives or by using the set
primitive to change its heading
parameter. In the model example below, we have a road represented with gray patches and a car on the road. We use the set heading 90
code in our setup procedure to make sure that our car is heading towards east. Our model has 3 different go buttons: go-slow
, go-fast
, and go-back
, each doing exactly what the name suggests.
xxxxxxxxxx
to setup
clear-all
ask patches with [pycor = 0][
set pcolor gray
]
create-turtles 1 [
set shape "car"
set ycor 0
set heading 90
]
reset-ticks
end
to go-slow
ask turtles [
forward 0.1
]
tick
end
to go-fast
ask turtles [
forward 1
]
tick
end
to go-back
ask turtles [
forward -0.2
]
tick
end
Once you mastered the forward
primitive, don't stop there. Check out the resources below to improve your NetLogo skills.
forward
primitive:create-links-with
Creates links with every agent in an agentset.