[NOT SOLVED!] Changing collision group & mask after creation

josephcooper
Posts: 3
Joined: Tue Jun 22, 2010 1:19 am

[NOT SOLVED!] Changing collision group & mask after creation

Post by josephcooper »

I have these current collision types:

Code: Select all

enum collisiontypes {
            COL_NOTHING = 0, //<Collide with nothing
            COL_WORLD = BIT(1), //<Collide with world
            COL_PLAYER = BIT(2), //<Collide with player
            COL_PLAYER_PROJECTILE = BIT(3), //<Collide with player projectile
            COL_PHYS_OBJ = BIT(4), //<Collides with objects
            COL_PICKUP_RAYTEST = BIT(5) //<For the raytest to pick up items
        };
And these masks:

Code: Select all

playerCollidesWith = COL_WORLD | COL_PHYS_OBJ;
    worldCollidesWith = COL_PLAYER | COL_PHYS_OBJ | COL_PLAYER_PROJECTILE;
    playerProjectileCollidesWith = COL_WORLD | COL_PHYS_OBJ | COL_PLAYER_PROJECTILE;
    physObjCollidesWith = COL_WORLD | COL_PHYS_OBJ | COL_PLAYER | COL_PLAYER_PROJECTILE | COL_PICKUP_RAYTEST;
    pickupRaytestCollidesWith = COL_PHYS_OBJ;
I was wondering how to change an object's group and mask in an application after an object has been created. Say I make an object with collisionworld->addRigidBody(blah,COL_PHYS_OBJ,physObjCollidesWith); and then want to change its group to COL_PLAYER_PROJECTILE and set its mask to playerProjectileCollidesWith. How would I do this? I have tried accessing the objects broadphase proxy and changing the m_collisiongroup and m_collisionmask directly but this didnt seem to work.
Last edited by josephcooper on Tue Jun 22, 2010 2:19 am, edited 1 time in total.
josephcooper
Posts: 3
Joined: Tue Jun 22, 2010 1:19 am

Re: [SOLVED] Changing collision group & mask after creation

Post by josephcooper »

Solved with setNewBroadphaseProxy().
josephcooper
Posts: 3
Joined: Tue Jun 22, 2010 1:19 am

Re: [NOT SOLVED!] Changing collision group & mask after crea

Post by josephcooper »

Ok, looks like it isn't quite solved! The object now proceeds to freak out i.e. twitching and weird behavior! Probably a result of setting a new broadphase proxy in the middle of running the app?

Code: Select all

        btTransform trans = holdObj->getWorldTransform();

        btVector3	minAabb;
        btVector3	maxAabb;
        holdObj->getCollisionShape()->getAabb(trans,minAabb,maxAabb);

        int type = holdObj->getCollisionShape()->getShapeType();
        holdObj->setNewBroadphaseProxy( world->getBroadphase()->createProxy(
            minAabb,
            maxAabb,
            type,
            holdObj->getPointer(),
            COL_PLAYER_PROJECTILE,
            playerProjectileCollidesWith,
            world->getDispatcher(),0
	));
User avatar
Erwin Coumans
Site Admin
Posts: 4221
Joined: Sun Jun 26, 2005 6:43 pm
Location: California, USA

Re: [NOT SOLVED!] Changing collision group & mask after crea

Post by Erwin Coumans »

You need to

1) remove the object from the world
2) add it to the world again with the new collision group & mask

Hope this helps,
Erwin