Click to See Complete Forum and Search --> : Advice requested: Actionscript concepts in creating ball game

03-20-2002, 07:26 AM
Greetings Flash-fiends,

I would appreciate a few words of advice before I embark on a considerable personal project.

I would like to simulate a ball game using a technique similar to the wonderful Conversion Kings (http://www.sportal.co.za/).

However, whilst I'm an ok programmer, and a good animator / artist, the mathematics side of this is really going to test me (yes, I was the guy who sat at the back of maths class drawing the teachers. Kids - I wish I had paid attention instead).

What I was hoping for from you guys is some kind of direction as to the mathematical factors I may have to consider, in creating something similar to Wireframes masterpiece, from scratch.

For example, my ball will need to be told its Xpos and Xpos, and I will have to simulate a Zpos to give the illustion of size. The Zpos will be largely dependent on a Power variable (ie how hard the ball has been struck). However, the Zpos (size / scale) reduction will need to slow down over time to create the appearance of perspective. Also, my ball needs to curve in the air (both through spin AND gravity). Does this mean a parabola?

Whew. I sat down last night with a pen and a paper, and realised how much thought this needs. Any assistance (in simplified language) would be a great help.

Many, many thanks in advance,

Lewis Boadle

Ed Mack
03-20-2002, 10:52 AM
Would it not be easier to make a simple 3d engine, and just manipulate the balls x,y and z? That way you could separate the maths from the presentation, and not worry about perspective :)

03-21-2002, 10:47 AM
Yeah Ed,

it may well be...

Which brings me onto my next question. Where can I get one of these, or, how do I go about making one of these?


03-22-2002, 03:53 AM
In a situation where gravity is the only force, two axis exhibit constant speed (x and z) and y exhibits constant acceleration (a=g) this does give a parabola.
If you want to have spin, you'll have your hands full. Spin creates curves in a totally different way. By increasing and decreasing pressure on opposite sides of the ball, the ball is literally beaten toward the low pressure side by piles of air molecules on the high pressure side.
First we address spin.
Take baseball. Call the line from the pitcher to the catcher the z-axis, up/down the y-axis, and left/right the x-axis. The simplification I would employ would be to assume the speed along the z-axis is constant, i.e. unaffected by spin, unslowed by air resistance. This is not a huge loss in rigor since a baseball pitch is never deflected more than say 10 degrees from the z axis.
So now you need only determine the angle of the spin. Choose the pitcher's point of view. Name the angle based on the direction spots all over the ball would appear to be travelling. So 0 deg spin would be top spin, 180 deg spin would be back spin. 90 deg spin would mean that the dots appear to be going right. Clear? Call the angle 'sigma'
Call the spin magnitude S(the speed of a scrap of leather on the surface of the ball relative to the center of mass of the ball)
So the acceleration in the y direction called ddy is affected by the quantity S*sin(sigma) and the acceleration in the x-direction is affected by the quantity S*cos(sigma)

Gravity is easier, but first let me a get a reaction from you on how clear I've made this first part... I know it's not code you can just patch into your movie but it didn't seem like that's what you were after.

Notice that one of the key things is the choice of perspective. The on I've chosen is great if the motion is roughly linear (as with baseball, pingpong) a back and forth situation.

Any of this help?

I really want to lend a little rigor to the M&P forum.