- Home /
AI positioning in soccer game
I am currently programming AI players for a soccer game. I want to ask what kind of algorithm should I use to create AI players that can find the best positions to block and steal the ball.
The game is in 2D
Thanks in advance.
Answer by DFledermaus · Oct 23, 2013 at 02:28 AM
In soccer the trick is the lines, the line from the player with the ball to the goal if they intend to attempt to score, or from one player to another if they intend to pass. Have each enemy player decide which is more likely based on player distance from the goal and from enemy players.
Then update the enemy player's AI script with a target direction toward one of these lines. Not the points at the end, you don't always want them running directly at the player for instance. They need to move to the nearest point on the line between the player and the player's expected objective.
This is an explanation of how to find that path.
And if you can, take the player's velocity into account, so use their present location multiplied by their speed per second multiplied by the number of seconds it would take the enemy player to get to that location, instead of simply their present location only.
Thanks for the info! I am beginning to understand how it works. Some of the questions, how do you position the AI along those lines? Vectors don't have positions. Secondly, the player's velocity, speed and time is for what?
You'll need to tweak the formula I linked to in order to make it return the target ins$$anonymous$$d of the distance to the target, or look around for other formulas that might be more precisely what you need.
You'll also need to combine it with another target, such as the player's location, so the enemy player doesn't just move to intercept and stop. Scale between the two depending on how aggressive you want the enemy to be.
Your answer
![](https://koobas.hobune.stream/wayback/20220613120454im_/https://answers.unity.com/themes/thub/images/avi.jpg)
Follow this Question
Related Questions
Distribute terrain in zones 3 Answers
Multiple Cars not working 1 Answer
Enemy AI C# 0 Answers
Another Raycast Issue. 0 Answers
stupid errors i can't figure out 1 Answer