This week I expanded upon the opponent AI to do more than just mark players. For this, I implemented a tackling mechanic as well as interceptions. Interceptions were pretty simple to implement as the player only needs to get close to a loose ball in order to take control of it, which is quite common during ball transitions. However tackling was more complex and is still being worked on.
In order to implement tackling, I first use to same scan function I implemented for player detection in order to detect the ball within a small view cone. If the ball is found within the view cone, we run the tackle logic, which essentially "pulls" the ball towards the player performing the tackle. This does look pretty clean at times but due to this being fully physics based, it has a tendency to send the ball flying off as the dribbling logic interferes with the force being applied to the ball; and I'm actively trying to improve this.
Here's a video showing off how the tackling mechanic should work in an ideal scenario.
A video showing off the weird physics behavior when a tackle is attempted. (Red debug cones are used to represent the view cone used when tackle requests are querying for the ball).
In addition to these mechanics to help improve AI, I also worked on improving the actual AI behavior itself. In order to do so, I made them less aggressive and instead moving in front of the player they are supposed to mark, they position themselves between their defensive goal and the player. Once the ball transitions into a loose ball state, they are now close enough to move ahead of the marked player and intercept the ball, if the ball is played in that area. What happens in the loose ball logic is that the AI coordinator determines which player is closest to the ball and sends that player towards the ball in order to intercept it. The remaining players move back to their anchor positions.
How I'm currently implementing opponents to be marked to each player.
The new loose ball logic that runs when neither team is in possession of the ball.
I also introduced a hashmap to ensure spacing out of players and more accurate assignments of players to mark for the entire team. As long as an opposition team's player's name is not present in the map, it means they are unmarked and if they are, we assign the player with closest anchor position to that position to mark them. Now we also assign a player to chase after the ball carrier in order to perform perform tackles.
Updated Defensive Logic to make the AI less aggressive, resulting in more interceptions and tackles.
A final product of this week's work which has less aggressive marking, but better ball turnovers.
The upcoming week I will be preparing for my final presentation and will be trying to make tweaks to a number of mechanics. Here are my priorities for the upcoming week/10 days leading upto the final:-
Improve how I'm determining the team in possession.
Resolve tackling issues.
Make interceptions better through path prediction and choosing a player closer to the predicted destination rather of having a player chase after the ball for a long time.
(Stretch goal) Improve the look of the project by adding animations to represent events such as passing and tackling better, improving environments and maybe using better player models.
Comments