[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: [pygame] physics basics?



Steve Grand's method has always seemed the most obvious to me..
(that book was very good, too :)

-----Original Message-----
From: Michal Wallace [mailto:sabren@manifestation.com]
Sent: 16 October 2002 19:11
To: pygame-users@seul.org
Subject: Re: [pygame] physics basics?


On Wed, 16 Oct 2002, Nicola Larosa wrote:

> > Can anyone point me to some good information on physics modeling in 2d
> > games?
> 
> There's a nice book from O'Reilly, with a sample chapter online:
>
> Physics for Game Developers
> http://www.oreilly.com/catalog/physicsgame/


You know, I bought this book, and was a little disappointed.
The math is descriptive of what actually happens, but I
don't believe these equations are the best way to model a
bouncing ball in a game. The equations emulate the effects
of real world physics, but equations don't cause balls
bounce. If I ever see a basketball whip out a calculator
before it bounces, I'll take that back :)

I thought a much better model was given by Steve Grand in
his book Creation: Life and How to Make it. (He's the guy
that developed the game Creatures)

Grand creates a world where at each tick of the clock,
simulated forces are applied to simulated objects. In other
words, rather than hard coding the bouncing equation, he
gives code for gravity and inertia and the correct path of
the ball emerges naturally.

Pythonized, his code looks something like this:

######

x, dx = 0.0, 10.0   ## start at left edge, moving right 10 units/tick
y, dy = 1000.0, 0.0 ## start at top, not yet falling

## while the ball is in motion:
while (dx or dy):

    ## calculate its new position:
    x += dx
    y += dy 

    ## simulate gravity:
    dy = dy-1 

    ## if the ball hits the floor:
    if y <= 0:

        ## don't fall through it!
        y = 0 

        ## friction slows ball in both directions:
        dx *= 0.7
        dy *= 0.7 

        ## also, the ball changes direction (bounce!):
        dy *= -1

    ## also bounce when it hits the right wall:
    if x >= 1000:
        x = 1000
        dx *= -1

    # drawBallAt(x,y) 

######

Elsewhere, Grand points out that the reason Newton had to
invent calculus was that he didn't have a computer to do
simple addition! :)


Cheers,

- Michal   http://www.sabren.net/   sabren@manifestation.com 
------------------------------------------------------------
Switch to Cornerhost!             http://www.cornerhost.com/
 Low Priced, Reliable Blog Hosting, With a Human Touch. :)
------------------------------------------------------------

____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org
____________________________________
pygame mailing list
pygame-users@seul.org
http://pygame.seul.org