Archived

This topic is now archived and is closed to further replies.

Sport games

This topic is 5625 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi, In sport games where players hit a ball (like NBA 2002 or volley games), how the ball path and collisions with palyers are managed? Is the ball path already predetermined? Does the pass from a player to an other use a path altrady predetermined (for example by an external tool)? In this case the animation (player hit ball) is simple to made, but if the ball path is calculated run-time, how the player animation can be synchronized with ball (i.e how can I decide when start the player animation using the ball position)? Thank you all for any suggestion! (Sorry for my English but I''m Italian). gnolo

Share this post


Link to post
Share on other sites
Different games use different schemes (and almost none of them ever publish their techniques), but most high-action sports games (basketball in particular) do a bad job of it anyway. Here's what I'd do:

  1. Each object that is involved in game play (players, ball, basket/net, court/pitch, etc) is of the same basic type, say PhysicalObject. This makes it easier to compute path intersections, collisions and resultant velocities, etc.
  2. Each PhysicalObject has the properties of mass, acceleration (linear, possibly angular if you want complex physics modeling), velocity (same as acceleration), position and any others necessary.

  3. The PhysicalObjects are then registered with a PhysicalManager which ensures that intense calculations are only performed on local (nearby) objects (it makes no sense to test for the collision of A's arm with B's head if they're at the opposite ends of the playing area), and than redundant computation is avoided (A collides with B => not necessary to test if B collides with A - commutative relationships).

  4. Now at regular intervals (whatever the "heartbeat" of your simulation is) you update all objects, applying incident forces due to collisions (player kicks ball => force applied to ball; player collides with other player => forces applied to both players) which translate to acceleration (F = m*a => a = F/m) and rotation (force not coincident with center of gravity, though if you consider your PhysicalObjects as particles then this is a non-issue). Acceleration changes velocity, which causes displacement of said object.


With regards to paths, use 3d vectors. If a player A kicks a ball in the direction of player B and player B moves away from that position, the ball should maintain its current motion. What this means is that the pseudocode for a PassBall routine would look something like this:
void Player:: PassBall(const Player & target)
{
vector3d dir = this->pos - target.pos; // used this to make it obvious
// apply force of magnitude "%age of player strength"
Ball.ApplyForce(this->strength * percentage_down, dir);
}

This also allows you to make your AI play more intelligently: smart ballhandlers will "estimate" the teammate's velocity and try to pass to a position just ahead so the teammate receives the ball "in rhythm":
void Player:: PassBall(const Player & target)
{
// perceptiveness is a measure of how accurately the current
// player estimates things
vector3d t_vel = target.velocity * this->perceptiveness;
vector3d dir = pos - target.pos;
long t = dir / vel;
dir += vel * t; // very crude estimate of future position
 
// apply force of magnitude "%age of player strength"
Ball.ApplyForce(this->strength * percentage_down, dir);
}

Because we used vectors we were able to simply add the displacement we anticipate the target covering in the time it takes the ball to travel to it.

That's a fairly brief introduction to what I like to term physical simulation and reasoning. From here we go on into making the AI respond intelligently (no pun intended!) to observable physical data and so forth.

(Sorry if the English is pretty loaded; it's hard to explain all of these concepts in very simple terms).

[edited by - Oluseyi on July 24, 2002 4:23:57 PM]

Share this post


Link to post
Share on other sites