Box2D collisions not being called on stand still objects

Discuss issues specific the Javascript port of Box2D
jamessimo
Posts: 5
Joined: Sat Jul 05, 2014 8:43 pm

Box2D collisions not being called on stand still objects

Postby jamessimo » Sat Jul 05, 2014 9:07 pm

Hey guys, I was wondering if anyone here could help me with this issue I am having.
I have some boxes that will float to the top of a block of water if they collide with the water. However, as you can see in the attached gif, the collision is not called if the blocks are at a stand still.

Image

I have set all the coloured blocks to awake and even set the world sleep to false but this hasn't changed anything. Is it an issue with blocks that move them selfs? (the water moves using SetLinearVelocity ).

Thanks in advanced and hope someone can shed light on this situation. (I am using the Google code version of box2dWeb version 2.1a.3)

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Box2D collisions not being called on stand still objects

Postby irresistible force » Sun Jul 06, 2014 8:43 am

Strange... it's obvious that all bodies are awake at least at some points, because you can see them move a little when they get bumped by the bodies you are dragging...
Do those other bodies start floating if you grab them with the mouse?
If you take out the check to see if the water is touching (and make all bodies float even when there is no water), all bodies will rise upward?
If you could remove that static body and reduce the example to just two bodies, might help to clarify the issue.
I would also recommend using debug draw display instead of your own rendered shapes, so that you can see if the bodies are actually sleeping or not (I know you intend that they are not sleeping, but perhaps for some reason they are).

jamessimo
Posts: 5
Joined: Sat Jul 05, 2014 8:43 pm

Re: Box2D collisions not being called on stand still objects

Postby jamessimo » Sun Jul 06, 2014 6:54 pm

irresistible force wrote:Do those other bodies start floating if you grab them with the mouse?


No, they have to go into to water (to fire a collision) so I if I move them in the water, this wont fire a collision.

I will try to re-create this using the debug draw and report my findings.

jamessimo
Posts: 5
Joined: Sat Jul 05, 2014 8:43 pm

Re: Box2D collisions not being called on stand still objects

Postby jamessimo » Tue Jul 08, 2014 10:56 pm

So I have enabled debug draw and it shows all bodies are awake (even the water) and I removed all other blocks so it was a single block and still nothing.

So the issue really seems to be that the collision handler is not being called on an object that has no velocity. If I give the blocks a velocity the collisions are called. I assume there is something LIKE sleep but different that tells the contact listener to ignore any stand still objects EVEN if they are AWAKE.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Box2D collisions not being called on stand still objects

Postby irresistible force » Wed Jul 09, 2014 2:53 am

Could you give a link or something to your cut-down sample using debug-draw? It might be a bug.

jamessimo
Posts: 5
Joined: Sat Jul 05, 2014 8:43 pm

Re: Box2D collisions not being called on stand still objects

Postby jamessimo » Fri Jul 11, 2014 9:50 pm

SO found the Issue, I don't know why this is, but switching around the fixtures (AB) inside the begin contact have solved this issue.

irresistible force
Posts: 1991
Joined: Tue Jun 24, 2008 8:25 pm
Location: Tokyo
Contact:

Re: Box2D collisions not being called on stand still objects

Postby irresistible force » Sat Jul 12, 2014 1:28 am

That's probably not a real fix, it may work for some cases but still fail in others. In the BeginContact, are you checking both possibilities for which fixture is water and which is a box etc.
Eg.

Code: Select all

if ( fixtureA is box and fixtureB is water )
    ...;
else if ( fixtureB is box and fixtureA is water )
    ...;

jamessimo
Posts: 5
Joined: Sat Jul 05, 2014 8:43 pm

Re: Box2D collisions not being called on stand still objects

Postby jamessimo » Tue Jul 15, 2014 10:49 pm

Yes I do do that.

Thanks for the help! I discovered this whiles making an empty scene to post here when I noticed the issue.


Return to “Javascript”



Who is online

Users browsing this forum: No registered users and 2 guests