Game Development Stack Exchange is a question and answer site for professional and independent game developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm not much of a maths expert, so this is probably quite straight forward. I was playing a soccer flash game where you take free kicks. You provide Power, Swerve and Direction. I'm reading up on vectors and such so I can use the direction and power information to shoot the ball with the correct velocity.

What I don't understand is how the 'Swerve' information is used. What formula connects the Swerve information with the Direction and Power? This is all assuming a 2D environment.

share|improve this question
up vote 5 down vote accepted

If, as AttackingHobo says, you're talking about spin, then the 'swerve' is known as the Magnus Effect. The ball is spinning, causing the air to travel faster on one side and slower on the other, producing a pressure difference.

Basically, the force exerted on the spinning ball (from the Magnus Effect alone) at a given time would be something like this

F = k * (w x v)

Where F is force, w should actually be an omega and is the rotation vector, x is just a cross-product operator, and v is the current velocity of the ball. k is some kind of constant factor depending on what kind of surface the ball has and so on, that one you basically have to try different values and see which fits.

The v vector is pretty straight forward, just the direction and speed of the ball. w (or omega) might seem unintuitive though, the magnitude is the rate of the spin (usually radians per second, but since we're multiplying with an arbitrary constant anyway, it might as well be RPM), and the direction is the axis around which the ball is rotating. To know which way is 'up', it's easiest to take your right hand and bend your fingers, the rotation is in the direction of your finger tips, and your thumb is basically the rotation vector.

In 2D, birds-eye perspective, a counter clockwise rotation would have the rotational axis pointing into your eye (away from the ground). You don't really need 3D stuff (like the cross product), buts it's easier to work the stuff out on paper and use zero all but one of the components (like z) to reduce the formula.

Also remember Newton, F = m*a, but again, the k is arbitrary, so we can just bake the mass into it, making a = k * (w x v). Where a is the acceleration (vector).

Birds-eye again, z pointing away from the ground (into your eye), x to the right, and y up the screen.

w = s*ẑ, v = (vx, vy), a = (ax, ay)

here I've used s as the spin (rate of rotation, positive being counter clockwise, denotes the unit vector in the z-direction).

ax = -k*s*vy
ay = k*s*vx

Long rant for a simple formula, hope it helps. :)

Note that back-spin will cause the ball to travel further, and top-spin will cause it to dive early, if that's something you want, you need to do the spin-vector in 3D.

share|improve this answer
Thanks a lot roe, the Magnus force is what I was looking for. Great explanation! – Skoder Mar 3 '11 at 18:28

Do you mean spin? Spin will cause the ball to swerve in the air.

In a true to life simulation, you would only apply a force to a spot on the ball from a certain angle, and the speed, spin, and direction would be determined from that.

In this soccer game, I am going to assume the graphics are 2d, but the view is facing the goal, and the ball graphic shrinks to provide depth.

So you need some sort of z depth at least.

The Swerve, or spin, causes the ball to change direction after it is hit. This allow for shots that look like they are going to end up to the right, but end up moving left.

So in the game make the swerve variable a float, and have it change the X direction on the ball, or what ever direction is left and right.

share|improve this answer
Thanks. Yes, I do mean spin. I thought of simply adding a direction in X, but I'd like to make it a bit more realistic in movement. What topics should I look into in order to gain the relevant information from the ball's initial impulse? (such as the spin, speed and direction) – Skoder Mar 3 '11 at 17:53

@roe above is probably the best answer. In real life it takes some amount of time for the fluid velocities to equilibrate to the motion of the ball through the air. So you could try to add some sort of time delay. My favorite is just exponential time damping. Swerve is just a some fraction of what it was the last time update, plus what you get from the current time update. So use roes: formulae for instantaneous swerve accelleration (or the current contribution), and combine say .05 times that to .95 times the previous result. Start the saved value at say 0, and you won't see much bending of the flight until several time steps have passed, which is kind of like a breaking ball in baseball, by the time the batter sees the balls trajectory deviate, it is too late to correct his swing.

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.