realbasic-games
[Top] [All Lists]

Re: Gravity, Physics etc.

To: REALbasic Games <realbasic-games at lists dot realsoftware dot com>
Subject: Re: Gravity, Physics etc.
From: Daniel Lurie <dl1021 at optonline dot net>
Date: Mon, 13 Dec 2004 17:52:50 -0500
Delivered-to: realbasic-games at lists dot realsoftware dot com
References: <1D4C1578-4D56-11D9-9E4C-000D9334D728 at mac dot com>
Gravity is fairly simple to implement. Give your character class properties called dx and dy. At the end of each frame, dx and dy are added to the characters' position x and position y.

When he jumps up, lets give him a dy of, say -5. Lets say gravity is +1 per frame.

Each frame do something like this:

myhero.dy=myhero.dy+gravity
myhero.y=myhero.y+myhero.dy

Watch what happens then:

Frm|dy|Height
-----+--+------
1     |-4|-4
2     |-3|-7
3     |-2|-9
4     |-1|-10
5     |0 |-10
6     |1 |-9
7     |2 |-7
8     |3 |-4
9     |4 |0

Gravity eventually makes dy positive and he starts to come back down. Play with the values til you get something that looks good to you.

On Dec 13, 2004, at 5:27 PM, Josh Farquhar wrote:

Hi again,
For my major project in software, I am programming a collection of mini-games. However, I have already hit a snag. I am not too good with advanced maths or physics or anything, so I am not sure how to program in gravity. The mini-game is one where you click on a ball to bounce it back up, before it hits the ground. http://www.neopets.com/games/zurroball.phtml is an example. I have managed some simple gravity code, where I add a certain number to a variable called VertVelocity, which I then add to the sprites Y position. This looks OK, but I know there must be something that will look a lot better. I also need the ball to bounce off walls etc. too. Any help would be appreciated! If I have missed out on telling you anything, just ask

-Josh

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>


============
Daniel R. Lurie
============
http://www.vikingdan.com

_______________________________________________
Unsubscribe or switch delivery mode:
<http://www.realsoftware.com/support/listmanager/>

Search the archives of this list here:
<http://support.realsoftware.com/listarchives/lists.html>

<Prev in Thread] Current Thread [Next in Thread>