Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / box2d question about bounciness

Author
Message
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2011 08:04 Edited at: 2nd May 2011 08:34
Say I throw a ball at a wall, I want the reaction with the wall to be completely dead. Kind of like when a billiard ball hits a "dead" spot on the table's cushions.

If the default value of restitution for a fixture is 0, then shouldn't it be completely inelastic? The ball would hit the wall then just drop straight down I would think?

Daniel wright 2311
User Banned
Posted: 2nd May 2011 08:14
Look, Im horrible to with spelling, always have been, but im not shure what you just said there.

my signature keeps being erased by a mod So this is my new signature.
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2011 08:20
Ummm, what? Wrong thread maybe?

mr_d
DBPro Tool Maker
19
Years of Service
User Offline
Joined: 26th Mar 2007
Location: Somewhere In Australia
Posted: 2nd May 2011 08:29 Edited at: 2nd May 2011 08:31
no, just mixing you "want" with one of your "walls"

and logically, that would be what i would expect, though i don't know anything about box3d to help.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 2nd May 2011 08:34
Ugh, I saw the error and went to correct it. Guess I changed the wrong one!

Sven B
21
Years of Service
User Offline
Joined: 5th Jan 2005
Location: Belgium
Posted: 3rd May 2011 00:41 Edited at: 3rd May 2011 00:46
I don't have any experience with box2D, but I have some with actual physics though.

If a ball is perfectly inelastic it will still bounce, but the angular velocity will not have an impact on the direction after bouncing (if I remember correctly). Also, the forces during the bouncing motion will be described using a Dirac function (which just means that we're saying that the bounce happens during an infinitely short time), while the "bouncing time" for elastic objects does exist. If a ball should fall dead, then it would mean that all the ball's energy is used for deformation and warmth. If the ball can't deform, then it would mean that the wall absorbs the whole shock, like a cushion.

Sven B

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd May 2011 01:40
If both objects have zero restitution and they hit straight on (ie. all the velocity is absorbed by the impact) they shouldn't bounce.

If either one has a restitution greater than zero they will bounce.

If you use extremely light objects they can bounce because the forces needed to separate the objects will be enough to bounce them apart. The solution is to try adjusting the units settings or increasing the density of the object.

All this is just guessing though until I can see some code

[b]
Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd May 2011 10:30 Edited at: 3rd May 2011 11:27
The ball has the default restitution because it needs to bounce off other things.

I suppose I could just check when it hits the wall and cancel out any forces.

It's not really that important, only needed it to make a demo of something while playing around.

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 3rd May 2011 11:37
Ok, the pinball tutorial showed me how to detect collisions by looping through the 3 bumpers and calling b2GetContact() and related commands.
Can't I just call those functions on the ball and see if it's made contact with the bumpers? It seems like that would cut down on loops, especially when I have more than 3 objects to check.



Will b2GetContact() return the ID of the contacted body? Or does it only return true or false as the documentation suggests? It's hard to learn this without the examples because the documentation is really nothing but a list of commands with a poor explanation about them.


My other question is how could I determine how much force one body hits with another body? That way I can "break" objects that are hit hard enough.

Diggsey
20
Years of Service
User Offline
Joined: 24th Apr 2006
Location: On this web page.
Posted: 3rd May 2011 23:33 Edited at: 3rd May 2011 23:41
There are too many contacts which are constantly being created and deleted for them to be treated the same as other objects, so the plugin uses a current contact system (a bit like the current bitmap in DBPro). All the contact commands work on the current contact.

b2GetContact just makes the next contact in a list the current contact. If there are no more contacts it returns zero, otherwise it returns one. There is no contact ID as such, just the current contact.

I tried to explain this in the help files for b2GetContact.

A body in box2d is made up of individual fixtures which define the physical shape. From a contact, you can get the two fixtures which collided with b2GetContactFixtureA() and b2GetContactFixtureB(). To get the bodies those fixtures belong to you can use b2GetFixtureBody() on each of them.

To get the "force" with which a collision occurs you can compare the velocities of the two bodies involved. Depending on how you want it to function you could take into account the masses of the bodies.

Quote: "Can't I just call those functions on the ball and see if it's made contact with the bumpers? It seems like that would cut down on loops, especially when I have more than 3 objects to check."


Yes, that's perfectly fine. I did it that way because it makes sense logically that if anything touches a bumper it should go off. Although in this case the only thing that moves is the ball, people might have wanted to extend the code in which case the bumpers would continue to function.

[b]

Login to post a reply

Server time is: 2026-07-11 12:20:21
Your offset time is: 2026-07-11 12:20:21