Saturday 30 April 2016

Some Vector Math

The problem is to allow the player to work out if if there is a dangerous obstacle (an opposing player) in his path whilst dribbling. This is similar to a "field of view" but just re-sized to what the player considers "too close for comfort." So when an opposing player enters the danger area, the dribbler will try to change direction or get rid of the ball.

Here's the vid:

Teaching myself vector math from the beginning again, there is probably a more elegant way to do this. Anyway, here's what my brain came up with.

Given the position of the player p, his normalized velocity v, an angle specifying how wide the field of view should be and a length specifying the size, we can calculate a triangular field of vision (three points, p1, p2, p3) like this:

p1 = p
p2 = v.rotate(angle/2)  x length
p3 = v.rotate(-angle/2) x length

With different parameters, this can also be used to select possible pass receivers etc.

Example in code:

// calculate the angled vectors
Vector3 side1 = position + velocity.rotated(-25, 0, 0).normalised() * 200;
Vector3 side2 = position + velocity.rotated( 25, 0, 0).normalised() * 200;

// p1 is just the position of the player
p1.x = position.x;
p1.y = position.y;

// p2 is end point of the first side
p2.x = side1.x;
p2.y = side1.y;

// p3 is the end point of the second side
p3.x = side2.x;
p3.y = side2.y;


For the uber curious, here's the rotated() function:

// ----------------------------------------------------
//  rotated
// ----------------------------------------------------
Vector3 Vector3::rotated(double a, double x_origin, double y_origin) {

a = RADIANS(a);

Vector3 rotated = *this;

rotated.x -= x_origin;
rotated.y -= y_origin;

double nx = cos(a) * rotated.x - sin(a) * rotated.y;
double ny = sin(a) * rotated.x + cos(a) * rotated.y;

rotated.x = nx;
rotated.y = ny;

rotated.x += x_origin;
rotated.y += y_origin;

return rotated;
}

Wednesday 27 April 2016

An Idea

Not very realistic, but fun. Player transfers to be done with an in-game browser on an Ebay type site.

Monday 25 April 2016

Demo

Check out the goal at 1:26 (change youtube speed setting to 2x for actual speed)
 

Tuesday 12 April 2016

Handy New Feature

Holding Player 1 Start + Left on the stick brings up the IP address for a few seconds.

Saturday 2 April 2016

Another Pressing Example

Of course, if the dribbler manages to change direction, then pressing players would recalculate their interception paths, so it might appear in the static screenshot that a simple turn by the dribbler would easily evade the pressers, but as soon as he does so, the pressing targets would also change to intercept his new run.

We can also tweak the values for how far ahead of the dribbler the pressers will project. Again, the static screenshot may make it seem like they are planning a path way too advanced of the ball, but in reality the dribbler is moving quite fast and will converge with the nearest interception circle in only a second or so.

[click to enlarge]


What we might want to do for less aggressive pressing players, is to extend a path from the initial calculated intercept point to the middle of the goal, and set the new target a percentage along this new line.  this would result in a kind of pressing that favors pushing the dribbler into the flanks whilst protecting the goal area.

Pressing Diagram

Just an explanation of what's going on.


More Pressing

Here is an example (with slow moving players for clarity) to show how a team with high pressing might work. This case shows a team that tries to press with three players at all times (the pressing is not initiated until a blue team player starts dribbling).

Pressing players are highlighted with a blue spot, their "intelligent" interception target is shown by a red circle.

The intercept algorithm has the nice side effect that different pressing players seem to work together and don't all just head for the ball - they head for where they think the ball will be when they get there - therefore you can see the red target circles kind of "covering" for each other.

For testing, the attacking player has been given perfect dribbling, and the pressing players don't tackle.