game physics - Cocos2d-x 3 - Disable collision between two bodies and detect when them separate each other -
i'm developing cocos2d-x game (version 3.8). game uses chipmunk physics , has static body works interruptor. interruptor enabled when body on it. interruptor disabled when bodies separate each other.
i want to:
- moving body don't collision interruptor. has cross interruptor no bounce
- i want detect when moving body separates interruptor
my first approach implementing oncontactbegin method. return false when 2 bodies in touch. way body crosses interruptor , not bounce.
the problem oncontactseparate method not called, because contact did not happen.
if return true in oncontactbegin method, oncontactseparate called , can detect it. problem body not cross interruptor, bounces.
[edit] more info
this scenario 2 sprites separated. ball can move , interruptor static body. ball on interruptor.
this scenario 2 sprites in contact , object1 (the ball) on interruptor. want detect 2 sprites separate each other.
any appreciated!
it seems me using box2d within cocos, i'll answer base assumption.
this do.
- my interrupter b2body* no bodydef dimensions defined or 0x0 dimension def.
- i set user data bodydef rectangle describes interruption area. way can have interruption area represented, not collide anything.
(optional) if want interruption area move around based on fake body assigned it, can updated after step function using below.
world->step(delta, 10, 10); (auto physicsbody = _world->getbodylist(); physicsbody; physicsbody = physicsbody->getnext()) { auto userdata = static_cast<node*>(physicsbody->getuserdata()); if(userdata != null) { // set interruptor area rectangle = physicsbody->getposition(); } }
to let rest of system know when have left interrupter store function pointer function want call when happens, when object enters interruption area flag saying "i'm in area" after that, first update step when it's not in area anymore fire callback , reset flags used point.
i hope helps. not giving lot of context want do, image helpful. when comes looking code has visual representation well.
[edit] based on behaviour want way did this. first thing know don't need physics collisions behaviour want. can using bounding box intersection tests , use flags , callbacks figure out rest.
i have object knows both ball , interrupter nodes. in update loop of object check if 2 intersects. set flag indicating "i in interrupter", next frame not in interrupter , flag still true call function assigned "leaving logic" in it, , set flag false.
Comments
Post a Comment