It still uses the controlRobot() method which make it rotate to its destination, move to it, rotate again to reach the ball, and hit it.
However, now, the robot checks collisions in real time, each time, before moving ( rotating is not concerned, as it can't be the source of collisions ). When a collision occurs, the movement is stopped.
Then, the AI avoids the obstacle :
In order to do this, the first step is to get the difference angle (purple arrow) between angle made with obstacle ( black line ) and robot's direction angle ( dotted red arrow ).
The objective is to avoid the obstacle with an angle of 90° ( that's to say move in the direction of cyan arrow ). The blue angle to rotate is calculated using the difference angle calculated before and its signum.
At this point I simply move the robot using a constant small distance.
To finish, I call again the controlRobot() method I spoke about on the beginning.
This way, the method can be called recursively if there are many obstacles on the way.
Problem : At this point there is still problematic cases that can block the AI to an infinite loop :
If the robot want to reach the ball on the other side of the hoop,here it will collide one hoop foot, avoid it, collide the other foot, and again and again, as it is too big to cross in the middle.
This cans also happen if there is not enough space between two balls.
Moreover, even if almost of the time the robot reach the ball, sometimes the AI needs to recalculate the path more times than it seems to be actually needed...




No comments:
Post a Comment