Apply Magnus force

Hey,

I'm new to Box2D and have been messing around with some simple example codes. I'd now like to do something slightly more complicated and am stuck. I have a particle (ball) and would like to make it so that when the ball is hit (I apply an impulse), the ball spins and curves round (due to Magnus force). What's the best way of doing this? I've tried applying angular velocity, but the simulation just explodes. Other times, the ball simply curves away from the origin but doesn't spin back on it's original path. I'm trying to simulate a free kick in soccer which you can 'curl' round the wall. Thanks for any help.
First off, the magnus force is due to air friction and pressure differences, which box2d does not emulate at all. All physics is calculated as though it was in a complete vacuum.

What I'd do:
Apply a force that is perpendicular to the ball's velocity and with a magnitude dependent on the ball's spin (angular velocity). Each time you apply the force, you damp the spin on the ball a little.

With gravity, it'd make the ball curve up or down, spin would wear off and then be pulled down by gravity. You'd need add a few constants to regulate how much force is caused by the spin and how fast it wears off.

Actually, this could be a pretty neat thing for my game!
Hope it helps, and tell me if something doesn't make sense.
Thanks a lot for the help. I understand what you mean, but I'm having a little trouble implementing it. I'm using C#, but any ideas what I'm doing wrong?

//This is called when the user shoots
Code:
football.ApplyAngularImpulse(4f);         
       
football.ApplyLinearImpulse(new Vector2(0f, 3.03f));


The ball moves up the screen. Each frame, I use this:

Code:
football.AngularVelocity *= (float)(0.5f  * (football.Revolutions * 2 * Math.PI));
football.AngularDamping += 0.8f;

football.ApplyForce(new Vector2(football.AngularVelocity * 0.5f, 0.0f),new Vector2(football.LinearVelocity.Y * -1, football.LinearVelocity.X));


When applying force, the two parameters are "force" and "point". I've applied a relatively arbitrary force at a point perpendicular to the velocity vector (AFAIK). I'm not great with physics, so I'm sure I'm making an obvious mistake somewhere. When I run this, the ball goes 'crazy' and bounces all of the place, eventually having its angular velocity suddenly stop.
I'm not sure if this is the correct way of doing things (but with the wrong numbers) or just plain wrong 😛

Thanks again for the help, it's much appreciated.
There's a few odd things in there for sure.
AngularDamping should be set once, on initialization. You wont need to alter AngularVelocity any either, and the way you've done it there would make it go berzerk! It multiplies itself with 0.5f*revolutions*2*pi each iteration! That gets huge fast.
Code:
football.AngularDamping = 0.8f;
That's all you need to cause a damping of 0.8f each time you call the b2World::Step function, so it'll slow it down all on it's own. No need to set AngularVelocity.

You're doing something pretty weird when you apply the force too.
The first argument is a vector with the force, but you've put the force on the second argument, which is the point of the force!
Do this instead:
Code:
float scaleMagnus = 1.0f; // Change this to increase or decrease the desired curve force.

Vector2 forceVector( -football.LinearVelocity.Y, football.LinearVelocity.X );
forceVector.Normalize() // Don't normalize if you want the football velocity to affect the curve force aswell.
forceVector *= scaleMagnus * football.AngularVelocity; // Multiply the vector with the spin and the scale

football.ApplyForce( forceVector, football.GetWorldCenter() ); // Not sure what the C# interface is for that function


I haven't tested it, but I think that should do it.

One more thing...
When you kick off the ball, it's rather unpredictable to throw a raw impulse at it like that. Multiply the force by the body's inertia or set it's AngularVelocity directly. This allows you to change the mass of the football and still get the same velocity result.
Code:
football.ApplyAngularImpulse( football.GetInertia() * impulse );
// or
football.AngularVelocity = 1.0f;

Same goes for setting the linear velocity of a body, although you should use the GetMass for multiplying the force or impulse instead in that case.
Thank you so much Zoomulator, this is a perfect foundation! I'll play around with various values and see what feels right. Just a side question, but whenever the ball collides with an object (like the screen edge), the whole system explodes. Is there some property I should set on the boundaries to ensure that the ball continues to bounce off normally?

Thanks again! 🙂
The forces that were added in my example shouldn't add up to anything explosive... My best guess is that the ball is given too much spin to begin with. Does it explode when it collides without the magnus forces added to it? If that's the case, I'm quite sure you should try a much smaller value for the spin.

If the ball spins frantically, friction will cause an explosive acceleration when it touches another object. Happened to me a couple of times when I started out with box2D.
If I remove the Magnus Force, it bounces normally. However, I think I've solved the problem. I changed the ball's coefficient of restitution to 0 (was 0.3 from previous attempts) and it doesn't explode anymore 😀 . Thanks for the help!

Original thread: https://box2d.org/forum/viewtopic.php?t=6642