Search code examples
netlogopatch

How to change the forward speed when near the objetctive netlogo


i have bird that can fly really long distances, so it has a foward of 5. However its not reaching its destination as flying in intervals of 5 makes it jump the mark. To solve it i tried this.

ask Buteo-platypterus[ face min-one-of patches with [pcolor = green ] [distance myself] ifelse distance patches with [pcolor = green] < 5 [fd 1][ fd 5 set energia energia - 5] ]

Distance expects an agent or patch but it's getting an agentset. How do i make the bird go slower when its near the destination?


Solution

  • ifelse distance patches with [pcolor = green][...] This line of code is your problem. You are asking the distance to all green patches, an agentsent, instead of to the closest green patch.

    ifelse distance min-one-of patches with [pcolor = green] [distance myself] [...]
    

    This should solve the problem. You could also use a local variable to not have to rewrite the same code over and over again (which can lead to mistakes)

    ask Buteo-platypterus [ 
       let destination min-one-of patches with [pcolor = green ] [distance myself] 
       face destination 
       ifelse distance destination < 5 [fd 1][ fd 5 set energia energia - 5] 
    ]