How to move a kinematic body?

Please don't post Bullet support questions here, use the above forums instead.
Post Reply
i7.strelok
Posts: 21
Joined: Fri Jan 20, 2017 10:44 pm

How to move a kinematic body?

Post by i7.strelok »

I try to develop my FPS-Game, I need to move the player, but if I use dynamic-body, I change its rotation too, I think that I need to use the kinematic-body, but ... how to move the kinematic body ? Or How to disable the other axes?

Code: Select all

void PlayState::createPlayer(){

   Vector3 size = Vector3::ZERO;	// size of the box
 
  
  Vector3 position = _nodePerson->_getDerivedPosition();
  position.y +=2;
  Ogre::Quaternion rotation = _nodePerson->_getDerivedOrientation();
  // Obtenemos la bounding box de la entidad creada... ------------
  AxisAlignedBox boundingB = _sceneMgr->getEntity("BoxPlayer")->getBoundingBox();
  size = boundingB.getSize();
 // size.y*=2;
  size /= 2.0f;   // El tamano en Bullet se indica desde el centro
 
  // after that create the Bullet shape with the calculated size
  OgreBulletCollisions::BoxCollisionShape *boxShape = new 
    OgreBulletCollisions::BoxCollisionShape(size);
  // and the Bullet rigid body
  _rigidBox = new 
    OgreBulletDynamics::RigidBody("rigidBox", _world);

  _rigidBox->setShape(_nodePerson, boxShape,
		     0 /* Restitucion */, 0 /* Friccion */,
		     30 /* Masa */, position /* Posicion inicial */,
		     rotation /* Orientacion */);

  _rigidBox->setLinearVelocity(
  _camera->getDerivedDirection().normalisedCopy() * 3.0); 
  _rigidBox->showDebugShape(true);
  _rigidBox->setKinematicObject(true);
  // Anadimos los objetos a las deques
  _shapes.push_back(boxShape);   _bodies.push_back(_rigidBox);
  
      
}

MOVE...

Code: Select all

       _rigidBox->enableActiveState();
        _rigidBox->getBulletRigidBody()->setLinearVelocity(btVector3(0,0,1));
        _rigidBox->getBulletRigidBody()->activate(true);
        _rigidBox->getBulletRigidBody()->translate(btVector3(0,0,10));

Wrapper: OgreBullet
Post Reply