Jump to content
• Advertisement

Archived

This topic is now archived and is closed to further replies.

physics, collision, and gravity

This topic is 5728 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I implemented physics, collision detection and gravity in engine. My question is in what order should I do them ? I have... if(detectCollision()) { doPhysics(); } doGravity(); translate(); In what order should these be called ? I tried various orders, some tend to make the ball jump higher every time but let a ball restingon an inclined plane slide down. While the other one I tried doesnt make the ball jump higher (jumps to same height each time) but the ball won slide down on an incline plane. Any ideas ? Nitzan ------------------------- www.geocities.com/nitzanw www.scorchedearth3d.net ------------------------- [edited by - nitzan on November 7, 2002 9:09:31 PM]

Share this post

Share on other sites
Advertisement
Well doGravity(); allways affects the ball so it should be done first then physics.

or

1. add the gravity vector to the balls motion vector

2. detect colition

3. if colition then reflect the balls motion vector relative to the normal of the plane that the ball colides with

4. if colition then multiply the balls motion vetor with something like 0.95

Hope this can help you solve the problem.

Share this post

Share on other sites
So you have a ball start out at a ceratain point in space with and an initial velocity vector. NOTICE: Gravity only affects the vertical component of the vector, horizontal component is independent and (if no friction in program)stays constant, unless you want the ball to gain velocity from collisions.

1. Lets say it starts out falling. So you reduce the balls height (according to the formula which i assume u know dx=1/2at^2) and increase the balls vertical component of velocity.

2. If you detect collision reflect the vector accordingly. And increase or reduce the magnitude of the vector (depending on friction, and or elastic and inelastic collisions). Rember the ball bounces off walls at equal and opposite angle.

Could stop myself from doing ascii diagram:

\.....|
.\....|
..\...| <----Wall
...\..|
...( )|
.../..|
../...|
( )...|

... And so on.
If you dont want your ball to stop, increase the magnitude of the velocity vecter a little with each collision

[edited by - snisarenko on November 9, 2002 1:10:26 AM]

Share this post

Share on other sites
usually gravity is considered part of physics. if you''ve set your physics up using kinetecs of motion equations everything is done for you and you don''t need a special doGravity() method

s(t) = 1/2a*t^2 + v*t + s

s(t) = position at time t
a = acceleration
v = last calculated velocity
s = last calculated position
t = time since you last calculated this equation

gravity is some amount of acceleration downwards. i.e. set the y value of your acceleration vector to some negative value. if you want gravity to "look" right, then you''ll be wanting to use that equation. you can certainly make it look right through trial and error tweaking, but why tweak when the equations defining motion have been worked out for you.

but, if you don''t want to change what you''ve got, then just doGravity right after doPhysics.....

-me

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Contributors

1. 1
Rutin
19
2. 2
3. 3
JoeJ
15
4. 4
5. 5
• Advertisement

• 21
• 19
• 11
• 13
• 17
• Forum Statistics

• Total Topics
631697
• Total Posts
3001764
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!