Weird bug in bullet

SoapyWet
Posts: 1
Joined: Tue Feb 18, 2014 11:31 am

Weird bug in bullet

Post by SoapyWet »

Hello,
I'm currently working on a project which has implemented bullet (2.81-rev2613).

The bug that occurs is that bullet will completely break without reason; I lose complete control of the rigidbody and it does not rotate properly anymore.

The current setup is a map which is a rigidybody with a BvhTriMesh collision shape, the player is a capsule rigidbody (but the same error occurs with a box aswell)

The world is setup as follows:

Code: Select all

this->m_broadphase = new btDbvtBroadphase();
this->m_collisionConfig = new btDefaultCollisionConfiguration();
this->m_collisionDispatcher = new btCollisionDispatcher(this->m_collisionConfig);
this->m_solver = new btSequentialImpulseConstraintSolver;
this->m_dynamicsWorld = new btDiscreteDynamicsWorld(this->m_collisionDispatcher, this->m_broadphase, this->m_solver, this->m_collisionConfig);
this->m_dynamicsWorld->setGravity(btVector3(0,-9.8,0));
this->m_GhostPairCallback = new btGhostPairCallback();
this->m_dynamicsWorld->getBroadphase()->getOverlappingPairCache()->setInternalGhostPairCallback(this->m_GhostPairCallback);
The map is loaded from a .obj and is created like so:

Code: Select all

btCollisionShape* collshp = collptr->m_BvhTriMesh;

btTransform* tTrans;
tTrans = new btTransform();
tTrans->setIdentity();
tTrans->setOrigin(btVector3(0,0,0));
collshp->setLocalScaling(btVector3(1.0f, 1.0f, 1.0f));  /// NEED TO CHANGE THIS
					
btDefaultMotionState* tMotion = new btDefaultMotionState(*tTrans);
btRigidBody::btRigidBodyConstructionInfo cInfo(0.0f,tMotion,collshp,btVector3(0,0,0));

btRigidBody* body = new btRigidBody(cInfo);
body->getWorldTransform().setIdentity();

this->m_LevelUserPtr = static_cast<void*>(new std::string("World"));
body->setUserPointer(this->m_LevelUserPtr);

this->m_dynamicsWorld->addRigidBody(body, SharedRsc::COL_RIGIDS, SharedRsc::COL_PLAYER | SharedRsc::COL_OWNGHOST | BIT(0));
The player like so:

Code: Select all

this->m_State = new btDefaultMotionState(btTransform(btQuaternion(0,0,0,1), this->m_SpawnLocation));
this->m_Inertia = btVector3(0,0,0);
BulletCollisionShapeCollection::m_PlayerBox->calculateLocalInertia(this->m_Mass, this->m_Inertia);

btRigidBody::btRigidBodyConstructionInfo ci(this->m_Mass, this->m_State, BulletCollisionShapeCollection::m_PlayerBox, this->m_Inertia);
this->m_RigidBody = new btRigidBody(ci);
this->m_RigidBody->getWorldTransform().setIdentity();
this->m_RigidBody->setSleepingThresholds(0.0f, 0.0f);
this->m_RigidBody->setActivationState(DISABLE_DEACTIVATION);
this->m_RigidBody->setAngularFactor(btVector3(0,0,0));

this->m_RigidBody->setRestitution(0);
this->m_RigidBody->setFriction(2.0);
this->m_RigidBody->setDamping(.5, 0.0);

this->m_GhostObject = new btPairCachingGhostObject();
this->m_GhostObject->getWorldTransform().setIdentity();
this->m_GhostObject->setCollisionShape(this->m_RigidBody->getCollisionShape());
And we move and rotate the player like so:

Code: Select all

Math3::NormaliseVector(totalMove);

if(isG){
	if(walking)
		totalMove *= 0.5;
	this->m_RigidBody->applyCentralForce(btVector3(totalMove.x, totalMove.y, totalMove.z) * this->m_groundMove);
} else
	this->m_RigidBody->applyCentralForce(btVector3(totalMove.x, totalMove.y, totalMove.z) * this->m_airMove);


this->m_State->getWorldTransform(transf);
transf.setRotation(transf.getRotation().slerp(btQuaternion(this->m_TargQuat.x, this->m_TargQuat.y, this->m_TargQuat.z, this->m_TargQuat.w), 0.2));
this->m_RigidBody->setCenterOfMassTransform(transf);
this->m_RigidBody->getMotionState()->setWorldTransform(transf);
this->m_GhostObject->setWorldTransform(this->m_RigidBody->getWorldTransform());
Thanks