• Advertisement
Sign in to follow this  

Help with Box2D ContactListener

This topic is 1803 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'm experimenting with Box2D and trying to make GTA 2 Game Play Clone as an exercise, now i get stucked with the ContactListener(BeginContact and EndContact) member function.

this is what i'm trying to do :

 

- Begin Contact

---- store a Vehicle pointer to a pointer variable in Character class.

---- Call drivehandler() function from Character class which will call acquireControl() function from Vehicle member function *

---- Set the player position to be the same as Vehicle position *

 

- End Contact

---- removing the Vehicle pointer value by giving NULL in its value

---- Call driveHandler() function from Character class which will call releaseControl() function from Vehicle member function. *

---- set player position back to its original position

 

The problem is EndContact always Called after BeginContact that's make Vehicle pointer back to NULL and make my game freeze because the Vehicle pointer variable no more store the Vehicle object pointer[*].

 

I think the way to solve that is by calling the driveHandler() later at the end of the loop or step.i don't know how to do that except passing the pointer of void function to a vector array and then call it later, but still confused about how to do that.

 

Any help will be very appreciated :)

 

 

Best Regards

- Surya

Share this post


Link to post
Share on other sites
Advertisement

You can't modify the state of stuff in the physics world during the step, when begin and end contact fires. The docs are very clear about this.

 

You need to cache the contacts in some kind of external list, as you describe and as also shown by example in the docs, then do any processing after the step has completed. As I say, the docs have a good example of this but basic idea is to just store the information from the contacts that you require and then process after you step the world.

Share this post


Link to post
Share on other sites

yes, i know that. what i want to do is to make a list of functions and then process it after the step has completed.

i just don't know how to do that. i'm thinking about using std::vector or array but i'm confused how to do that for a function list. i've also doing some research but it's make me more confused

 

Update : Problem solved, Thanks :)

Edited by Fs02

Share this post


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

  • Advertisement