Player capsule movement on terrain heights

Started by
2 comments, last by Medo Mex 11 years, 4 months ago
I have First Person Shooter camera setup, I notice a problem when the player (btCapsule) go down from the terrain heights to the ground.

btCapsule cause the player to fall from the terrain heights instead of moving normally which is not a character behavior, I'm trying to get the character to move on the heights normally.

When I set a higher gravity, the player appear bouncing on the terrain while going down (from height to ground).
Advertisement
That's usually what happens when your forward vector only rotates around the y-axis and only represents a direction along the (x,z) plane.
Here is what I use to move the capsule forward:
D3DXMATRIX matRot;
D3DXMatrixRotationYawPitchRoll(&matRot, D3DXToRadian(rotationX), D3DXToRadian(rotationY), D3DXToRadian(rotationZ));
D3DXMATRIX ZUnitVec;
D3DXVECTOR3 vecForward;
D3DXMatrixTranslation(&ZUnitVec, 0.0f, 0.0f, 1.0f); // Matrix holding position of vector pointing to positive z
D3DXMATRIX m = ZUnitVec * matRot;
vecForward = D3DXVECTOR3(m._41,m._42,m._43); // Get vector from the matrix

X -= (elapsedTime * speed) * vecForward.x;
Y -= (elapsedTime * speed) * vecForward.y;
Z -= (elapsedTime * speed) * vecForward.z;

// -- Move btCapsuleShape forward
body->translate(btVector3(X - trans.getOrigin().getX(), Y - trans.getOrigin().getY(), Z - trans.getOrigin().getZ()));


How can I fix it to make the capsule move normally on the heights?
Hmm, I tried changing the line:
D3DXMatrixTranslation(&ZUnitVec, 0.0f, 0.0f, 1.0f);

To:
D3DXMatrixTranslation(&ZUnitVec, 0.0f, 1.0f, 1.0f);

Now, I don't see the problem anymore, is that the correct way to move forward?

This topic is closed to new replies.

Advertisement