Reputation: 45
This is a predator prey simulation with raptors and humans. I want the Raptors to move directly to the nearest human when in range. How to implement this in netlogo? Any suggestions?
Upvotes: 1
Views: 1246
Reputation: 641
To add an alternative to Seth's suggestion, if you were wanting the raptors to move immediately to the targeted human and then immediately eat them, you could try :
ask raptors [
let candidates humans in-radius 5
if any? candidates [
let target min-one-of candidates [distance myself]
move-to target
ask target [die]
]
]
If you wanted the raptor to gain anything (energy, etc.) you could put it in a line between the move-to and ask target commands. If you wanted the human to do anything when eaten (yell out for other humans to run, etc.), you'd put it in the brackets after the ask target command but make sure to put it before die or else the die command executes first.
Upvotes: 2
Reputation: 30453
Suppose you want a range of 5, and suppose you want the raptors to move one step towards the nearest human per tick. Then:
ask raptors [
let candidates humans in-radius 5
if any? candidates [
let target min-one-of candidates [distance myself]
face target
fd 1
]
]
Upvotes: 5