Ball flight simulation

Started by
4 comments, last by halt 22 years, 6 months ago
How can I simulate the physical correct ball flight for the Volley-ball game.
Advertisement
A rather wide question!

Firstly get a physics book which deals with the motion of projectiles.
Secondly, convert the projectile equations of motion into discrete form with a discrete time interval.
Thirdly, code the equations in whatever language you are using.

Once you''ve attempted this, come back and ask a more pointed question.

henry
HenryLecturer in Computer Games TechnologyUniversity of Abertay DundeeScotlandUK
Yeah, henryx is right. Start small. If you write a simulator that just treats the ball as a simple projectile it''ll probably be good enough. The big challenge will not be simulating the projectile flight path, but in detecting and responding to collisions (with the ground, players hands, ...).

Anything beyond simple projectile motion for a volleyball might not be noticeable on screen, but if you really want to go extreme you could include the effects of airflow (drag, and lift if the ball is spinning), the effect of the deformation of the ball. Perhaps the most important effect to add beyond simple motion would be decent friction forces in the collision response. That''s a deep subject, and you should get the basics working first.

Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
quote:Original post by henryx
A rather wide question!

Firstly get a physics book which deals with the motion of projectiles.
Secondly, convert the projectile equations of motion into discrete form with a discrete time interval.
Thirdly, code the equations in whatever language you are using.

Once you''ve attempted this, come back and ask a more pointed question.

Hmm, thanks, daddy but I don''t want to invent the bicycle again, may be there are some kind of sources, which can show it to me???
Just do a search for Projectile Motion.
Projectile motion, neglecting air resistance, is pretty simple. There is just a constant force being applied to the ball downward, which makes it accelerate downward. The x/z component of the velocity remains constant.

Then you need to simulate bounces. To do this, just scale your vector by -1. This is far from being an accurate physical simulation (unless your tennis ball is a subatomic particle, lol), but it should be decent for your purposes.

The ball, though, as you can see, will keep on bouncing forever. You may want to just scale the velocity by 0.02 every time it bounces or something. It's kind of a hack, I know, but it should suffice.


Now, in slightly more understandable English:

The ball moves along the x axis a certain amount each second, along the y axis a certain amount, and along the z axis. These three numbers (called the axial components of a vector ) are stored, and are added to the ball's xyz coordinates each frame/second/timestep. You subtract a fixed amount from the vector's vertical component each timestep to simulate gravity. Then, if the ball's vertical coordinate is below 0 (we'll say the court is a horizontal plane at 0) then you multiply the x and z components of it's vector by -1 for a perfectly elastic bounce (if a rubber ball never stopped bouncing) or by a negative number greater than -1 like -0.5 to make it lose some energy. In real life, in an inelastic (the ball doesn't bounce back with quite as much force as it hit the ground) collision, it wouldn't bounce back in exactly this direction, but this should work well enough. Then, when the player hits it with a racket, you'll need to determine what direction it was hit in, and add that force vector to the ball's velocity vector. When the components of the ball's velocity are all 0, the ball is "dead."

I hope that helps.

I'd still recommend, as henryx did, though, to get a physics textbook!

Edited by - TerranFury on November 3, 2001 6:02:58 PM

This topic is closed to new replies.

Advertisement