Jump to content

Box2D collisions not being called on stand still objects


jamessimo
 Share

Recommended Posts

Hey guys, I was wondering if any box2D (javascript) users 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. This function works fine



//if inside the water
this.waterObj.GetBody().SetLinearVelocity(new b2Vec2(0,-2));

I want my water take the boxes like a wave, however when the water block collides with the boxes, the collision handler is NOT called… 


 


However if I drop my boxes into the water it works fine (even if the water block is moving) 


 


I think this is to do with the collision handler not being called on my blocks if they are stand still, I have set


the 



bodyDef.allowSleep = false;

at creation and even reiterated throughout the boxes to check that sleeping is off; but this hasn’t changed anything, I even set the whole world sleep to false.


 


Can anyone help me get the water collision handler to trigger if it hits my stand still (not sleeping) blocks? Cheers!


Link to comment
Share on other sites

  • 2 weeks later...

at creation and even reiterated throughout the boxes to check that sleeping is off; but this hasn’t changed anything, I even set the whole world sleep to false.

 

 

 

 

do you mean they are actually sleeping and allowSleep = false; does nothing, or do you mean doing this doesn't actually fix your problem?

 

Could it be that you are using the wrong collision handler? You have BeginContact and PreSolve

Link to comment
Share on other sites

Oh forgot to mention that I fixed this problem by doubling the AABB collision handler.

the box would be fixutre A if clicked but if it was collided by the water it would be fixture B. So now I just say somthing like 

if(contact.fixtureA == box || contact.fixtureB == box){//THEY ALL FLOAT}
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...