Jump to content
  • Advertisement
Sign in to follow this  
cptrnet

Physics Question

This topic is 4815 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

Hi, I'm having trouble thinking of how to make my box bounce( or in my case not go through another box). Lets say I have a box thats 10 by 10. and I have a box below it thats 100 by 10. The first box is falling at a velocity of 1. The way I have it right now it that it just sets the velocity to 0, the gravity is still going so it goes right through the box, so I set that to zero, and now its right in the middle of the second box before it stops. The first thing I guess i need to do is to pull them apart and then make sure the gravity doesn't make it go through. Then I need to check the velocity and see how much it will bounce. The second box I am acting like its the ground so it wont ever move. Any suggestions would be appreciated, thanks.

Share this post


Link to post
Share on other sites
Advertisement
In the future you are likely to find yourself with a second box landing on the first one, and then the first one dissapearing, or being shoved away ... then you have a nasty problem trying to turn gravity back on. Just in general, it's best to handle this kind of situation even if you aren't currently expecting it... not always, just generally... it makes for more robust code. Turning gravity off should leap out at you as a "hacky" thing and you will regret it later.

However, for your case, to bounce, simply multiply the vertical velocity by -1. And yes, you should move the box to outside the ground when you detect the collision.

Share this post


Link to post
Share on other sites
Well if your update loop goes something like this:

- Update position,
- Check for collisions, resolve penetration if any.

Then you should not need anything more.
You are not going to get any realistic results with this approach unless you update the position using the box velocity and resolve the penetration by acting on the same velocity.

Could you be more specific as to what exactly you are trying to achieve? I assume it is 2d but do you need to consider angular effects or just linear motion?

Share this post


Link to post
Share on other sites
It's 2d, I am trying to get the box to bounce of the ground. I want to say if the box can bounce then do so. But still almost everything bounces, Isn't depending on density of the object and velocity.

Share this post


Link to post
Share on other sites
I don't understand what I need to do. That code has a bunch of other things in it, that I don't understand yet, so I don't know what to look for or what I need to do. Thanks for the post though I will try to go through the code and pull out parts I think will work. Is there a physics tutorial website that takes you through step by step first with collision detection of all shapes, and then goes into physics? The ones I've found are way too confusing.

Share this post


Link to post
Share on other sites
The link glSmurf gave you is from the website of Chris Hecker - he has a lot of info there:

http://www.d6.com/users/checker/dynamics.htm

See if you can make sense of his physics articles (especially the first 3). From what I can remember, these are good articles, worth reading and putting in a bit of effort to understand.

Basically, making boxes bounce around isn't as simple as you might think.

Also, if you're intending to stay in 2D and use simple shapes for collision, then the verlet/particle approach might be suitable for you - description here:

http://www.gamasutra.com/resource_guide/20030121/jacobson_01.shtml

(you might have to register, but it's worth it because there's other good stuff on Gamasutra).

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

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!