let the ball move ...
Posted 30 July 2012 - 10:06 AM
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 ...
Posted 30 July 2012 - 05:08 PM
Posted 30 July 2012 - 08:05 PM
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).
If you don't know how to speed up application, go "roarrrrrr!", hit the compiler with the club and use -O3 :D
Posted 31 July 2012 - 08:54 AM
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