[Solved]Collision problems

majc

19-08-2010 14:05:18

After the player and npc bodies collide, the player body passes below the npc body.
Any idea because this is happening?
The mass value is 80.0f and the gravity is -9.8f.
By the way I'm using the gravity in the setMassMatrix instead of the player mass because for some reason, this way when i increase the mass of the player he becomes heavier and more heavier he gets harder is to jump, this way is more realistic, for some reason when i use the gravity instead in setMassMatrix i can't see any changes in the jump when i change the player mass, this has nothing to do with the problem because i tried to use the mass and the player body still passes below the npc body.

Here is the code:

void cNonPlayerCollisionHandler::setCustomForceCallback(OgreNewt::Body *body, float t1, int t2)
{
Ogre::Vector3 force = cPhysicsInterface::getSingleton().getGravity() * mEntity->getMass();
cPhysicsInterface::getSingleton().addLocalForce(body,force, Ogre::Vector3::ZERO);
}

OgreNewt::PlayerController* cNonPlayerCollisionHandler::createNonPlayerController(Ogre::Entity *entity, Ogre::Vector3 size, Ogre::SceneNode *node)
{
Ogre::Vector3 inertia, offset;

OgreNewt::ConvexCollisionPtr col = cPhysicsInterface::getSingleton().createCollisionConvexHull(entity,0);
OgreNewt::Body* body = cPhysicsInterface::getSingleton().createOgreNewtBody(col);
cPhysicsInterface::getSingleton().calculateInertialMatrix(col,inertia,offset);

#ifdef OGRENEWT_NO_COLLISION_SHAREDPTR
delete col;
#endif
body->setContinuousCollisionMode(1);
cPhysicsInterface::getSingleton().assignBodyToNode(body,node);
cPhysicsInterface::getSingleton().setMassMatrix(body,cPhysicsInterface::getSingleton().getGravity().y,inertia);
cPhysicsInterface::getSingleton().setCenterOfMass(body,offset);
cPhysicsInterface::getSingleton().setPositionOrientation(body,Ogre::Vector3(0.0f, 0.0f, 0.0f), Ogre::Quaternion::IDENTITY);
// set the player to always be active
cPhysicsInterface::getSingleton().setAutoSleep(body,0);
body->setCustomForceAndTorqueCallback <cNonPlayerCollisionHandler>(&cNonPlayerCollisionHandler::setCustomForceCallback,this);
OgreNewt::PlayerController *mNonPlayerController = new OgreNewt::PlayerController(body, 0.4f);
return mNonPlayerController;

}


Thanks in advance!

shaolin

22-08-2010 10:42:34

While I haven't had a lot of time analyzing the code, it may be because the mass is much greater than 1 (Bullet recommends that you keep masses close to 1).

Again, I haven't used OgreNewt much and it could be totally acceptable in that engine. Hope this gives you some direction.

majc

22-08-2010 13:25:46

Thanks mate for your reply, i found the solution but i forgot to put it here sorry :S

The problem was the stairs factor of OgreNewt::playerController it must be near 0 because it's not working very well.