Jump to content
  • Advertisement
Sign in to follow this  

Complex movement patterns in sports games

This topic is 2346 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

Dear all,

I am trying to write a little basketball game in C++. I know how to make my guys move around the pitch using speed vectors and time deltas. What ails me is how to make them perform less straightforward movement patterns, such as a crossover move. I want the player to move slightly to the right with the fake, then quickly move left and explode forward.

I am only representing players with circles, so I don't care about animations at this point. Just calculating their position on the floor.

Only thing I can come up with is to hand craft an array with the player's positions at sequential points in time, but it feels sort of hacky. Also, the movement will look unnatural when the player comes to a waypoint and heads towards the next; it will look as if he bounced off a wall. Is there a better way to do this?

Cheers!

Share this post


Link to post
Share on other sites
Advertisement
Hi!

I assume most modern games use motion captured animations so I guess your waypoint approach isn’t so far off. If you feel ready to take the leap to animations, you probably end up using some sort of key frame representation and blend between the time steps anyway.
So the question is: how to move smoothly from waypoint to waypoint, right?
The common solution for this is a spline interpolation. A spline is a sequence of curves, which are stuck together. For animations you want three things from the curve:
  • You want to visit each way point (this is called interpolation property).
  • You want the tangent to be smooth (this is called C1 continuity), so no sharp corners.
  • You want the speed when you’re passing a joint to be continuous (this is called C2 continuity). So not abruptly accelerating or decelerating.Usually you are using cubic splines, since they have low polynomial degree. This prevents numerical issues and the curve will “behave”. Curves of high degree tend to make some weird detours.

    If you want to compute cubic interpolating C2 continuous splines you have to solve a linear system of equations. Sure, you could do this for your animation, but perhaps it is too much effort to put in.
    So, instead you often give up the last of the three aforementioned constraints.

    Very common is the usage of cubic Hermite splines. Those are cubic polynomials, too, but they only provide you C1 continuity. If you distribute your waypoints well enough, you won’t get any problems. For a Hermite interpolation, you need two waypoints and for each waypoint a direction vector telling you from which direction you like to pass through it. Code is here (about line 659).

    Alright, so how to choose those direction vectors? Very, very common with animations is to use Catmull Rom splines which are a special case of Hermite interpolations. Here the vectors are chosen from the previous and the next way point. Assume you have four waypoints w1, w2, w3, w4, then the direction at w2 is d2 = w3-w1 and at w3 it is d3 = w4-w2. Code is here, too. (about line 698).

    Hope this helps!

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!