# let the ball move ...

3 replies to this topic

### #1AticAtac

Member

• Members
• 87 posts

Posted 30 July 2012 - 10:06 AM

I am trying to simulate a soccer ball. I already know all the maths and physics (magnus effect, etc.) behind.
Right now i have just an understanding problem with velocities:
the ball moves in a certain direction x,y (lets assume its not flying so no 3rd dimension) by having 2 velocities for x and y axis.
My problem is now that once the velocity in one direction gets zero (cuz of friction and other forces) the ball still moves on one axis which then looks strange cuz it then starts to move only horizontaly/verticaly depending on which velocity gets zero.

Maybe someone can bring some clarity in this ...

### #2}:+()___ (Smile)

Member

• Members
• 169 posts

Posted 30 July 2012 - 05:08 PM

You don't have right equation for friction and other forces. In the simplest models friction is always oppositely directed to the velocity vector, so all components must go to zero in the same time.
Sorry my broken english!

### #3Vilem Otte

Valued Member

• Members
• 345 posts

Posted 30 July 2012 - 08:05 PM

Okay, I'm not the physicist expert (e.g. it's been a while i passed nuclear and quantum physics on school) but...

Note: Warning this post might contain stuff you already implemented, but because I've implemented a physics engine before (even though I currently mostly use ODE) - I strongly recommend building good interface and have decent code base first (it will save you from having this-like problems, because it looks like you're decreasing friction/drag just in one, not in both dimensions) - so it's more like advice how to...

First of all don't implement magnus effect, etc. (it won't work properly unless you simulate Navier-Stokes equations of sorrounding of football playground (be it stadium or not)), unless you have decent base.
So my advice is, start building from ground up with simple steps - e.g. simulate just basic Newton physics ignoring wind, etc. (those equations will work for any N-dimensional space then!). Build the system the clever way - e.g. allow user of system to do Object.AddForce, Object.AddTorque - this will make things a lot easier when developing and adding F.e. Magnus effect (through hacky way... unless you actually do physics simulation).

Moving the ball according to Newton laws is quite simple - for each iteration there is static force of static size applying on it (the gravity = 9.81 m*s^-2), also there is static force of dynamic size - the air drag (F_drag = Newtons_constant * area * air_density * speed^2 / 2 - fore more info see here http://en.wikipedia..../Drag_(physics)). When the ball hits something you need something called Elastic collision equations - conservation of momentum and conservation of kinetic energy - for more info see here - http://en.wikipedia....astic_collision - also when elastic collision has almost zero effect and the ball is just rolling on surface, don't forget to apply friction - http://en.wikipedia.org/wiki/Friction.

When you got everything mentioned implemented, then you got basic physics engine (assuming that you can handle collision detection - Sphere-Triangle is quite simple one + google for Sweep Sphere-Triangle when the sphere speed isn't that high so you can start rolling and applying friction). With this the ball motion will be quite good (note. most games are actually using just this) ... so it'll be time to add more things - like interaction between ball and wind (e.g. adding further stuff) and optimizing the stuff (like building BVH for geometry so you'll do less number of Sphere-Triangle tests).
My blog about game development (and not just game development) - http://gameprogramme...y.blogspot.com/

If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D

### #4AticAtac

Member

• Members
• 87 posts

Posted 31 July 2012 - 08:54 AM

Thanks for the answer.
Indeed i found the problem in my routines: i was checking each velocity individually for droping below a threshold and make it zero. Now i use the velocity-magnitude (sqrt(vx*vx+vy*vy+vz*vz)) and it seems to work. But you are right, things like Magnus force still doesn't work properly and to be honest i don't need wind too (still need magnus force).
I will try your suggestion, though i am not sure if i still need an ODE-solver like runge-kutta or not.

#### 1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users