I am simulating pedestrian motion in NetLogo, and am having trouble creating an obstacle avoidance algorithm from scratch. There are algorithms online but they are not suited for moving obstacles (other pedestrians). In addition, my agents are moving from their spawnpoint (point A) to their goal (point B).
This is my NetLogo algorithm:
globals [ wall walkway center dest ]
turtles-own [ gender goal velocity spawnpoint mid turn ]
to setup
clear-all
ask patches[
set wall patches with [
(pxcor > 3 and pycor > 3) or
(pxcor < -3 and pycor > 3) or
(pxcor < -3 and pycor < -3) or
(pxcor > 3 and pycor < -3)
]
set walkway patches with [
(pxcor > -4 and pxcor < 4) or
(pycor > -4 and pycor < 4)
]
set center patch 0 0
]
ask patches [
set pcolor black
]
ask walkway [
set pcolor 9
]
crt population [
set velocity 0.1
set mid 0
set gender random 2
if gender = 0 [set color red]
if gender = 1 [set color blue]
set spawnpoint random 4
if spawnpoint = 0 [ move-to one-of walkway with [not any? turtles-here and (pxcor < -11)]]
if spawnpoint = 1 [ move-to one-of walkway with [not any? turtles-here and (pycor > 11)]]
if spawnpoint = 2 [ move-to one-of walkway with [not any? turtles-here and (pxcor > 11)]]
if spawnpoint = 3 [ move-to one-of walkway with [not any? turtles-here and (pycor < -11)]]
set goal random 4
while [ goal = spawnpoint ] [ set goal random 4 ]
if spawnpoint != 0 and goal = 0 [set goal patch -16 0]
if spawnpoint != 1 and goal = 1 [set goal patch 0 16]
if spawnpoint != 2 and goal = 2 [set goal patch 16 0]
if spawnpoint != 3 and goal = 3 [set goal patch 0 -16]
]
reset-ticks
end
to decelerate
ifelse velocity > 0.01
[ set velocity velocity - 0.01 ]
[ rt 5 ]
end
to accelerate
if velocity < 0.1
[ set velocity velocity + 0.01 ]
end
to go
ask turtles [
ifelse patch-here != goal[
set turn random 2
if distance center < 3 [ set mid 1]
if mid = 0 [ set dest center ]
if mid = 1 [ set dest goal ]
face dest
ifelse any? other turtles-on patches in-cone 1.5 60
[ if any? other turtles-on patches in-cone 1.5 60
[ bk velocity
rt 90 ] ]
[ accelerate
face dest
fd velocity ]
]
[ die ]
]
end
The simulated environment of this simulation is an intersection:
https://i.stack.imgur.com/Jp7cO.png
(sorry, I need 10 rep to post images :( )
Image 1 shows the state of the environment after setup. Image 2 shows what happens after the agents move to their goal (goal != their spawnpoint). The agents facing the different directions shows the agents which made its way past the clutter of agents in the center and are now on the way to their goal. The agents in the center, however, are stuck there because of my algorithm. The simulation is more problematic when there are more number of agents, which means they will just clutter in the center of the environment and just stutter when moving.
I based my algorithm on http://files.bookboon.com/ai/Vision-Cone-Example-2.html . Forgive my algorithm, I started programming in NetLogo a week ago and until now I still don't have the proper mindset in programming in it. I'm sure there's a better way to implement what I have in mind, but alas I am frustrated upon trying many implementations that came to my mind (but never got close to the real thing).
P.S: This is my first post/question in StackOverflow! I hope my question (and my way of asking) isn't bad.