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