For this version I have added something that was in the original Football Superstars game – Space Passing. This allowed you to target a team mate and use the spacebar to pass the ball directly to his feet, even if he was running.
To get this to work you have to resort to some mathematics. You know the start position of the ball and you can also get the position of the target player.
My maths sucks, so I researched the required formula online and created a method in Unity (I’m using the C# scripting language) to make this calculation which is called whenever you hit the spacebar in the game.
For the moment, the receiving player is static. However, he will return the ball to you after about 1 second. This version doesn’t take your velocity into account so you need to be static when receiving the ball. However, the AI will locate you if you even if you have moved and return the ball to your feet.
The ball still uses the Unity physics engine, but the required velocity and angle to reach the target is pre-calculated. Once the receiving player detects the ball at his feet he will capture it and control it to stop it going any further.