Page 1 of 1
Collisions aren't automatic ?
Posted: Tue Sep 22, 2015 1:41 pm
by Furya
Hi,
So I Created my world, my collisionShapes, my rigidBodies,... and we can see it with debugDrawer. It works but when I move my character towards an another object, a tree for exemple, my character penetrate inside it. why ? Bullet doesn't have to stop the character when there is contact ? or it's to me to code that ? I thought that when I create rigidBodies in a same world, Bullet works alone and stop when there is collision between entities... Can you explain to me what i have to do ?
sorry i'm french
Re: Collisions aren't automatic ?
Posted: Wed Sep 23, 2015 4:35 pm
by drleviathan
Yes, the character should collide with the tree automatically by default. There must be a bug in your program, but you have not supplied enough information for us to figure out why. You would have to supply some code or a more detailed description of how you build/move the character and tree. Some questions that come to mind:
(1) How does the character move? Are you using btKinematicCharacterController or something else?
(2) What shape types are being used for the tree and character?
Re: Collisions aren't automatic ?
Posted: Wed Sep 23, 2015 7:23 pm
by Furya
thank you for reply
I use ogreBullet.
(2) What shape types are being used for the tree and character?
So for my character i use a collisionBox
Code: Select all
AxisAlignedBox boundingB = mPJ->mEntityCorps->getBoundingBox();
Vector3 size = boundingB.getSize(); //size /= 2.0f; // only the half needed
//size *= 0.96f; // Bullet margin is a bit bigger so we need a smaller size
// (Bullet 2.76 Physics SDK Manual page 18)
// after that create the Bullet shape with the calculated size
OgreBulletCollisions::BoxCollisionShape *sceneBoxShape = new OgreBulletCollisions::BoxCollisionShape(size);
defaultBody = new OgreBulletDynamics::RigidBody("defaultBoxRigid2",mWorld);
defaultBody->setShape(mPJ->mNode,
sceneBoxShape,
0.6f, // dynamic body restitution
0.6f, // dynamic body friction
70.0f, // dynamic bodymass
Ogre::Vector3(mPJ->mNode->getPosition().x, mPJ->mNode->getPosition().y, mPJ->mNode->getPosition().z), // starting position of the box
mPJ->mNode ->getOrientation()) ;// orientation of the box
defaultBody->enableActiveState();
mWorld->addRigidBody(defaultBody, 0, 0);
For the tree I use a triangleMeshShape
Code: Select all
// collisionShape
AxisAlignedBox boundingB = mSceneMgr->getEntity("Arbre0")->getBoundingBox();
Vector3 size = mSceneMgr->getEntity("Arbre0")->getBoundingBox().getSize(); //size /= 2.0f; // only the half needed
//size *= 0.96f; // Bullet margin is a bit bigger so we need a smaller size
// (Bullet 2.76 Physics SDK Manual page 18)
SceneNode *node = mSceneMgr->getEntity("Arbre0")->getParentSceneNode();
OgreBulletCollisions::StaticMeshToShapeConverter *smtsc = new OgreBulletCollisions::StaticMeshToShapeConverter();
smtsc->addEntity(mSceneMgr->getEntity("Arbre0"));
OgreBulletCollisions::TriangleMeshCollisionShape *collisionShape = smtsc->createTrimesh();
//RigidBody
OgreBulletDynamics::RigidBody *defaultBody = new OgreBulletDynamics::RigidBody("defaultBoxRigid",mWorld);
defaultBody->setShape(node,
collisionShape,
0.6f, // dynamic body restitution
0.6f, // dynamic body friction
0.0f, // dynamic bodymass
Ogre::Vector3(node->getPosition()), // starting position of the box
Quaternion(180, 0, 0, 1));// orientation of the box
defaultBody->enableActiveState();
mWorld->addRigidBody(defaultBody,0,0);
(1) How does the character move? Are you using btKinematicCharacterController or something else?
I use Ogre to move my character ? I did'nt know btKinematicCharacterController.
Re: Collisions aren't automatic ?
Posted: Thu Sep 24, 2015 9:20 pm
by Furya
I tried Kinematic Object for my character with
Code: Select all
defaultBody->setKinematicObject(true);
defaultBody->disableDeactivation();
but I penetrate inside this tree. I don't understand.
Re: Collisions aren't automatic ?
Posted: Fri Sep 25, 2015 5:04 am
by drleviathan
A "kinematic" object is movable but moves in a non-physical way. That is, its motion is defined by some external source that is independent from the physics dynamics. Hence, kinematic will pass right through other kinematic and static objects... if the code that dictates their motion says they do. You know those platforms that move around in scrollers and various level-games? You can bounce dynamic objects off of them but you can't stop their motion -- it is determined by some script. Those are "kinematic" objects.
A "kinematic character controller" moves the character around kinematically, but also provides some collision detection and changes the kinematic motion accordingly. That is what you want to use.
A little research online reveals this
Ogre forums post about how to do it. I followed the link to the tutorial and looked it over. The character's collision logic happens in the
CharacterController_Physics class which appears to be a slightly modified version of
btKinematicCharacterController.
Note: the
btKinematicCharacterController class in the Bullet API is rather buggy. I don't view it as a proper part of the API but as a Demo class that was accidentally added to the API side. I wouldn't recommend using it, but you might try to understand what its doing and then write your own. Alternatively you could look a bit harder than I did an try to find other character controller implementations for Ogre.