This week involved making the AI make smarter decisions based primarily on opponent player positioning. Expanding upon the foundation I laid down last week, each individual player is responsible for scanning their surroundings and reporting it to the AI coordinator which behaves as a blackboard of sorts, with shared information across players on the same team.
Using this information, if a passing lane to a player is obstructed by an opponent, they picked a random location to move to open up the angle. This obviously resulted in non-deterministic behavior and the players shuffled into several bad positions before eventually getting to a decently open position.
In order to address this, whenever the passing lane to a player was obstructed by an opponent, they try to find a better position to move to by rotating the vector drawn from the player with the ball to that player by the angle formed between the player, the player with the ball and the opponent; plus a certain minimum angle to open up slightly more space than required. This guarantees that they are now open to receive a pass from the ball carrier.
How players logically move into more open spaces to receive passes.
Code snippet of how a more open location away from an opponent is chosen.
Additionally, the direction of movement around the opponent player (clockwise vs anti-clockwise) is determined by doing a cross product between the direction vector from the player to the opponent and the player's forward vector and observing the resultant vector's z value to determine whether the opponent player is to the right or the left of the player.
Determining if a point is to the right or left of a player using cross product.
The final result of this week was the almost complete elimination of players shuffling to find a better position and instead moving to a better location deterministically. This makes the gameplay look more natural and resemble an actual match of FIFA. There are still issues to address like checking if the chosen position is obstructed by a different opponent player and making sure that players don't go too close to other teammates, simply as this would reduce passing options for the player with the ball. These are the challenges I am hoping to address during the upcoming week.
Video demonstrating the better AI system taking up better positions deterministically.
Comments