Changing collision group causes object to get stuck?

Megadanxzero
Posts: 13
Joined: Fri Sep 07, 2012 9:50 pm

Changing collision group causes object to get stuck?

Post by Megadanxzero »

Hi, I'm trying to make an object temporarily switch to not colliding with certain objects, but it seems that when I do so the object simply gets stuck and will no longer move at all. From a quick look on the forum it seems the best way to change a collision group/mask is to remove and re-add the object with the new group or mask, so I'm just doing this:

Code: Select all

mp_DynamicsWorld->removeRigidBody(mp_RigidBody);
mp_DynamicsWorld->addRigidBody(mp_RigidBody, CM_IGNORED, btBroadphaseProxy::AllFilter);
(AllFilter is one of the default masks, apparently not used by Bullet, but it's just defined as -1, so it's a nicer, instantly understandable value than just putting a -1 in there)

It seems to work fine in terms of actually changing the collision group (Objects without CM_IGNORED in their mask will not collide with the object), but the object itself completely stops moving for some reason. I had a look at the rigid body's values and it seems like the gravity and velocity are what they should be (Not 0) and yet the object just doesn't move... The weirdest thing is that if I change the object's collision group back to what it originally was (Again by removing and re-adding the object) it works fine again. The problem is I obviously need the object to react normally in the time between changing group and changing back.

Am I wrong in thinking that those default masks aren't used and can be overridden with my own? I assume my method of changing the group is fine since it does appear to filter out the right collisions, and works normally when reversed. Any ideas? :(

EDIT: Ok it seems I wasn't quite right about it working fine after reversing it. It seems to work most of the time, but not all the time, which makes this seem even weirder...
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Changing collision group causes object to get stuck?

Post by xexuxjy »

Is it possible that the object is becoming inactive? adding / removing will update the broadphase proxy with the new masks , and I believe that they can be anything you want so overriding them should be fine. Might be worth giving the object a kick by setting it's activation state when you add it in again as I don't think that will be reset.
Megadanxzero
Posts: 13
Joined: Fri Sep 07, 2012 9:50 pm

Re: Changing collision group causes object to get stuck?

Post by Megadanxzero »

Unfortunately I already tried calling activate() on the rigidbody, but it doesn't seem to make any difference. I'm not sure where the activation state is stored in a RigidBody/CollisionObject (I can't seem to find it) but I assume it should be activating fine if I call activate() and it has non-0 gravity and velocity. I thought maybe the collision flags could be changing, but those seem to stay the same too (Just 0 at the moment) :(
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Changing collision group causes object to get stuck?

Post by xexuxjy »

the activation state is in isActive / setActivationState - so might be worth querying that to check, from looking it seems that activate will only work on non static or kinematic objects , unless you do activate(true) to force activation. can't think of many other reasons why it would just stop.
Megadanxzero
Posts: 13
Joined: Fri Sep 07, 2012 9:50 pm

Re: Changing collision group causes object to get stuck?

Post by Megadanxzero »

Err, yeah for some reason I was trying to look for the actual value after putting in a breakpoint, not sure why I didn't just call isActive()... Brain no work today? <.<

But yeah, isActive() is returning true even when the object is stuck, so it doesn't seem to be an activation issue. It might also be worth mentioning that I'm changing the mass of the object at certain points, but I haven't had any problems with this until I tried to change the collision group, so I assume that isn't what's causing this. I guess it could be the combination of the two, but from a quick look at the RigidBody it seems like the mass and collisiongroup values are both what they should be...
xexuxjy
Posts: 225
Joined: Wed Jan 07, 2009 11:43 am
Location: London

Re: Changing collision group causes object to get stuck?

Post by xexuxjy »

Hmm, is your mass 0 when you re-add the object by any chance? that would force bullet to think it was a static object.
only other thing to look for is if it's generating BroadphasePairs that contain your object, and to check what the linear and angular velocity values are.
sorry, just guessing now.
Megadanxzero
Posts: 13
Joined: Fri Sep 07, 2012 9:50 pm

Re: Changing collision group causes object to get stuck?

Post by Megadanxzero »

Aaaah yeah you were right, I was intentionally setting the mass to 0 to make the object static in some situations, but previously the mass had been non-0 when it was initially added so I was able to make the object static and then change it back to being dynamic again. I guess if the mass is 0 when you call addRigidBody it's set as being a static object forever, so it wasn't working when I was switching it back. That explains why it was working in some situations, those must have been times where the mass was non-0 when it was removed and re-added. I've solved it by temporarily setting the mass to be non-0 when I remove and re-add the rigid body to change the collision group, and then setting it back to 0 if necessary.

Thanks for the help! :3