Jump to content

  • Log In with Google      Sign In   
  • Create Account


Help with Box2D ContactListener


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
2 replies to this topic

#1 Fs02   Members   -  Reputation: 382

Like
0Likes
Like

Posted 12 February 2013 - 09:37 AM

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


[my game in #ggj14 : http://www.indiedb.com/games/romance-stalker [my blog : http://surya.volge.net ]


Sponsor:

#2 Aardvajk   Crossbones+   -  Reputation: 5935

Like
1Likes
Like

Posted 12 February 2013 - 12:47 PM

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.



#3 Fs02   Members   -  Reputation: 382

Like
0Likes
Like

Posted 13 February 2013 - 06:54 AM

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, 13 February 2013 - 08:40 AM.

[my game in #ggj14 : http://www.indiedb.com/games/romance-stalker [my blog : http://surya.volge.net ]





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS