0

I am currently working on a small game using OpenGL (Windows, Visual Studio). For physics I use the BulletLibrary.

The Setup in OpenGL:

  • floor: A "hilly" terrain model (in Bullet btBvhTriangleMeshShape)
  • player: A model of a small animal (btCollisionSphere in Bullet)

Currently the controls work as follows:

// method lies in the Player class
if (glfwGetKey(window, 'W')) {

        // btRigidBody
        playerBody->setLinearVelocity(btVector3(dirWorld.x, -1, dirWorld.z) * timeDelta * moveSpeed);
        btTransform trans; 
        playerBody->getMotionState()->getWorldTransform(trans);//->getWorldTransform(trans);

        // sets the location in the current model matrix
        setLocation(glm::vec3(trans.getOrigin().getX(), trans.getOrigin().getY(), trans.getOrigin().getZ()));
}

where dirWorld is a normalized direction vector, pointing from my player model forward (looking direction). The -1 for the y-Coordinate is necessary so when moving down the player sticks to the terrain and does not float down.

What I would like now, is that the Model would rotate according to the slope of the terrain: - even -> stay horizontal - up -> rotate so head is higher than tail - down -> rotate so head is lower than tail

My idea would be to take the Rotation of the CollisionShape and "transfer" it to the actual Model.

What my question(s) is(are) now:

Can I achieve this with a CollisionSphere, or would I then have a rolling model as well?

Or should I use a completely different CollisionShape for my character?

Or is there another way to do this altogether?

genpfault
  • 51,148
  • 11
  • 85
  • 139
seBaka28
  • 932
  • 1
  • 7
  • 16
  • Perhaps related to [this](http://stackoverflow.com/questions/18345710/how-do-you-control-a-player-character-in-bullet-physics) and [this](http://stackoverflow.com/questions/25605659/avoid-ground-collision-with-bullet/25725502#25725502)? I've never seen a perfect character controller for any physics engine. – jozxyqk Jun 17 '15 at 10:33
  • Have seen and read those already, however they only deal (as far as I understood it) with how to make the character stick to the floor, not how to rotate it according to current level of slope of the terrain – seBaka28 Jun 17 '15 at 10:41

0 Answers0