Netlogo turtles move and angle - netlogo

I want to move my turtles and I want that they don't go out of my field.
For example, If turtles 1 have to attack the goal that is in the right place of the screen, I don't want that the turtles 1 that is in the left side go out from the field and reappear on the right side(and viceversa).
I initial found a possibile solution by set the goal position, and use :
facexy-nowrap goal-xcor goal-ycor
But It doesn't help me because I use this command only for attack behavior, and I prefer to not use it...
So there is another solution? like using field lines?

Related

How do I make linked turtles move together in NetLogo?

I'm trying to model fish movement and need them to form schools when there is more than 1 of the breed in a given patch. So far I have managed to get them to form links when they encounter each other with the function below, but then they continue moving independently. I'd also like to re-scale the color of turtles in a linked group so that the more turtles in the group the darker the color is (I'm guessing this is similar to the way you make contour maps according to environmental gradients but I haven't figured it out yet).
Any assistance is always appreciated!
to form_link
if count breed_1-here > 1
[
ask breed_1
[create-links-with other breed_1-here]]
end
If linking isn't the way to get them to move together, I'm fine with another method.

Move to the opposite location of a detected turtle

I have an agent mouse and an agent cat.
When a mouse detects the presence of a cat around him, I want the mouse to rotate to the opposite positions where it detected the cat.
You can make one agent face another with face. You can then make the agent turn around with rt 180. The result will be that they're facing exactly away from the other agent!
When you have the option of multiple cats there might be a problem when running away from just one of them...
In that case you might want to make some weighted new direction, depending on the cats in the surroundings. But then your definition of the 'empty directions' and possible problems with multiple groups of cats coming in from different directions...
alternatively, you just move-to one-of neighbors with [count cats-here == 0]
(which will probably cause a run-time error if all neighbors harbour a cat.. :-)

netlogo turtles moving on coordinates

I created turtles called "birds" that shall move on a specific route. The route is made out of links between turtles I called "rasts". As I couldn't find a way to make the turtles move from the first rast to the second, third, fourth and fifth, I changed the rasts an created them as patches.
So, now I have patches in red (rests).
How do I get the birds moving to exactly these patches and, when they are at the patch, how do I make them go to the next one?
I have no code at the moment, because I always hope to find the fault in my first model (see my other questions).
Is there anybody who knows how to solve my problem?
the move-to command moves your turtle to any other turtle or patch you specify. You can also use the face and forward commands to gradually move along a route (see the 'Move Towards Target' code example in the Models Library that comes with NetLogo)

How to give turtles directional commands when moving along a drawn out network?

I want turtles to be able to flow along the paths I have drawn out for them. To do this I think it might be a reasonable idea to have a list in the u.i that allows the user to select a preordained direction of movement for that patch so the turtles know how to flow along the network. Has anyone else produced a model with this feature? If so would it be possible to give an example of the relevant source code for implementation into my own project?
I did something a while back where each patch had a direction variable that turtles set their heading to when on the patch.
Something like
patches-own[dir]
to go
ask turtles [set heading dir fd .1]
end

What is the difference between face and towards?

I have used face in NetLogo without any problems, but isn't towards just the same? (in the context of an agent facing towards the direction of a patch/agent)
towards
towards agent
Reports the heading from this agent to the given agent.
If wrapping is allowed by the topology and the wrapped distance (around the edges of the world) is shorter, towards will use the wrapped path.
Note: asking for the heading from an agent to itself, or an agent on the same location, will cause a runtime error.
set heading towards turtle 1
;; same as "face turtle 1"
See also face.
Is there any scenario in which using set towards heading is better than using face?
towards only reports the heading
face is like towards and set heading combined into one.
Are there circumstances in which you would like to know the heading towards something without actually turning to face it? I'm sure you could think of many. One example situation would be choosing between two possible headings according to some criteria.
Let's say you want to face one of two agents, whichever one requires you to turn the least amount:
let first-heading towards first-agent
let second-heading towards second-agent
; compare my current heading to the two calculated headings:
let first-angle subtract-headings heading first-heading
let second-angle subtract-headings heading second-heading
if-else abs first-angle < abs second-angle
[ rt first-angle ]
[ rt second-angle ]
(In real life, you would probably do things a bit differently, but I hope this carries the point across.)