Advertisement

Troubles with a Bouncing Ball...

Started by May 21, 2001 10:39 PM
1 comment, last by ogracian 23 years, 8 months ago
Hello, I am trying to do a simple simulation of a bouncing ball agains different walls, somthing like a mini golf, but I am having troubles trying to find which way the ball must bounce after one wall collision, I have heared that it can be acomplished with Vectors and using the Dot product in some way but I am really stuck on it so I really appreciate any help. My main trouble is how can I find which Direction the ball must go after one collision. Thanks in advance!!
In a simple 2D example where x- and y-velocities are represented as integer (or float) variables vx and vy, collision with a vertical boundary (left or right) means it''s time to reverse vx (vx = vx); with a horizontal boundary (top or bottom), flip vy instead. This is how Pong (and most of its clones) was made.

In a generic 3D application, however, where you may choose to include frictional attenuation or gravity, the solution is simply. So simply, in fact, that you may wish to apply the same technique to 2D, just dropping the z-coordinate.

The direction and velocity of a particle can be represented by a sinlge vector, the magnitude of the vector being the velocity while the vector direction is, obviously, the particle direction. Given two vectors A and B, representing the particle and the normal of the surface with which collision occurs, the new particle direction, a vector C, is the vector sum of A and B (ie C = A + B). That''s it. Cx, Cy and Cz will describe the amount of x- y- and z-axis motion for the particle, while the magnitude sqrt(Cx*Cx + Cy*Cy + Cz*Cz) will represent the total velocity.
Advertisement
Thanks for your reply. It help me a lot!

This topic is closed to new replies.

Advertisement