How to disable collision on and object (toggle temporarily on/off)

148 views
Skip to first unread message

Pierre Chamberlain

unread,
Jul 29, 2014, 10:23:00 AM7/29/14
to nape-p...@googlegroups.com
What would be the best way to temporarily disable a "body" for collision?

I'll describe the situation - I have this "peggle" style game where the ball may collide with a barrel's edges at the bottom of the screen.


















In the attached mockup picture, you can see the two "cyan" kinematic boxes that "tracks" to the barrel's movement (these are manually moved according to the Sprite's x & y position).

If the ball touches the boxes, I give an Impulse to the ball, and also move it up slightly (to guarantee it only touches the barrel for one frame and bounce off of it).

However, if the ball touches on the exterior edges of the boxes (outside of the barrel, while the barrel is moving fast in the same direction as the ball), the ball "sticks" to the box until either the barrel slows-down, stops or starts moving in the opposite direction.

So I figure, maybe I should just ignore any collisions on the kinematic boxes if the ball is greater-than > a certain y-position on the stage.
But how do I disable their collisions? Do I have to change their CbType's? Their InteractionFilters? the CollisionGroup / CollisionMask?

Also, I intend to use a sensor inside in middle of the Barrel. At that point I guess I can either just not run the simulation, but it would be nice to know if Sensors can be disabled as well.

Thanks!

-Pierre

Pierre Chamberlain

unread,
Jul 29, 2014, 10:35:41 AM7/29/14
to nape-p...@googlegroups.com
Actually, seems like using Body.disableCCD is a much better approach for what I'm after. My Impulses are firing correctly and the side edges of the kinematic boxes are no longer sticking the ball!

Would still be interested in an answer for disabling collisions though if anyone knows.

Jarkko Syrjälä

unread,
Aug 20, 2014, 5:41:52 AM8/20/14
to nape-p...@googlegroups.com
Here's one way of doing it:

private function initListeners():void {
space.listeners.add(new PreListener(
InteractionType.COLLISION,
BARREL_CBTYPE,
CbType.ANY_BODY,
barrelPreCollisionHandler,
/*precedence*/ 0,
/*pure*/ true
));
}

private var collisionEnabled:Boolean=true;
private function barrelPreCollisionHandler(cb:PreCallback):PreFlag {
if (collisionEnabled) {
return PreFlag.ACCEPT;
}
else {
return PreFlag.IGNORE;
}
}
Reply all
Reply to author
Forward
0 new messages