Move Towards Target Example
Model was written in NetLogo 5.0.4
•
Viewed 1799 times
•
Downloaded 230 times
•
Run 7 times
Do you have questions or comments about this model? Ask them here! (You'll first need to log in.)
WHAT IS IT?
This code example demonstrates how to have a turtle approach a target location a step at a time.
HOW IT WORKS
The people breed has a variable called target, which holds the agent the person is moving towards.
The face command points the person towards the target. fd moves the person. distance measures the distance to the target.
When a person reaches their target, they pick a random new target.
Comments and Questions
Please start the discussion about this model!
(You'll first need to log in.)
Click to Run Model
breed [people person] people-own [target] breed [houses house] to setup clear-all set-default-shape houses "house" ;; CREATE-ORDERED-distributes the houses evenly create-ordered-houses number-of-houses [ fd max-pxcor ] create-people number-of-people [ setxy random-xcor random-ycor set target one-of houses face target ] reset-ticks end to go ask people [ ;; if at target, choose a new random target if distance target = 0 [ set target one-of houses face target ] ;; move towards target. once the distance is less than 1, ;; use move-to to land exactly on the target. ifelse distance target < 1 [ move-to target ] [ fd 1 ] ] tick end ; Public Domain: ; To the extent possible under law, Uri Wilensky has waived all ; copyright and related or neighboring rights to this model.
There are 8 versions of this model.
Attached files
| File | Type | Description | Last updated | |
|---|---|---|---|---|
| Move Towards Target Example.png | preview | Preview for 'Move Towards Target Example' | over 12 years ago, by Uri Wilensky | Download |
This model does not have any ancestors.
This model does not have any descendants.
Download this model