Reaction of collision

kksmart

25-08-2008 15:58:58

I want do someting when the collision happen , for example , I want reduce the life when leading actor contact the weapon , what should I do ? thanks!

SiWi

25-08-2008 16:00:50

You need a collision callback. :D

kksmart

25-08-2008 16:55:33

thanks very much , but which code can help me to do it , I can't find relational codes in ogrebullet 's demo .

SiWi

26-08-2008 09:51:59

Unfortunatley, I have no OgreBullet code for you, as I'm not even developing in OgreBullet, but pure bullet and I'm using Python not C++. :(

seroom

31-08-2008 14:08:54

You have to use raw bullet.
Have a look at: http://www.bulletphysics.com/mediawiki-1.5.8/index.php?title=Collision_Callbacks_and_Triggers

It should go more or less like this:


static bool myContactAddedCallback(btManifoldPoint& cp,const tCollisionObject* colObj0, int partId0, int index0, const btCollisionObject* colObj1, int partId1, int index1)
{
switch( colObj0->getCollisionShape()->getUserPointer() ) // use user pointer to recognize objects
{
case ACTOR: ...
}
...
}


enum ObjectsIds{ ... , ACTOR , ... };

extern ContactAddedCallback gContactAddedCallback;

MyWorld::init(){
...
gContactAddedCallback = myContactAddedCallback;
...
mWorld = new DynamicsWorld(...);
...
mBody->getCollisionShape()->setUserPointer((void*) ACTOR);
mBody->setCollisionFlags(mBody->getCollisionFlags() |
btCollisionObject::CF_CUSTOM_MATERIAL_CALLBACK);
...
}

kulebril

03-01-2013 09:26:18

Hi!

Im currently using Bullet with Ogre, and I implemented the addedContactCallback like you said, but it keeps being called continously.
Is there a way for being notified only on first contact and on contact destroyed? (i mean, from bullet, yes, i know i could keep track and such).

thanks! :D