[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Bouncing ball - separating the physics from the frame rate



Matt Smith wrote:
I can see how it could fall down when I introduce non-horizontal or vertical surfaces. although I imagine that I could keep using the vectors but convert them into angular vectors on collision.

There's no need to calculate angles even then. Take a unit vector
perpendicular to the surface, and find the dot product of that
with the velocity. This is the magnitude of the component of the
velocity perpendicular to the surface. Multiply the unit vector
by that and add it to the original velocity (assuming your unit
vector points "away" from the surface).

As a general rule, it's almost never necessary to deal with
angles when doing this sort of thing. There's usually some
combination of vector operations that will give you what you
want much more easily and efficiently.

This is even more true in 3D, where angular coordinate systems
(so-called Euler angles) have various nasty problems due to
singularities. It's better to stay with cartesian coordinates
if at all possible.

--
Greg