I am working on a simple 2D soccer game, while passing the ball between my players I would like to check if any of the enemy players can intercept the ball, what I would like to do is calculate a list of coordinates between my players a corridor so to speak and then check if any enemy players are in this region,
-------------------------- S S --------------------------
It is easy to calculate the area between Ss when they lie like this, but how do I calculate the region when they are not aligned,
/S /
/ /
/ /
/ /
/ /
/ /
/ S/
EDIT: When I mean area, I want the list of coordinates in that region so that I can check those coordinates against players coordinates, not the magnitude of the area.
(image) http://img441.imageshack.us/img441/9051/soccer.png
Show enemy is between red lines: Calculate the distance of the enemy to the line formed by the two players (dotted line). If it is
<= w/2(wis the width of your “region”), then either the enemy is within the region, or behind one of the players.Show enemy is between orange lines: To check that he is not behind one of the players, just check that he is between the two lines which pass through one of the players and are normal (perpendicular) to the first line (the dotted line passing through both players).
This will tell you if the enemy is within the yellow region: