# Player Falling on Terrain Heights Instead of Moving

This topic is 2031 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

When the player move on the terrain heights (mountain), the player fall on the terrain instead of moving normally, which make the player appear like they are able to fly, see the attached picture.

Here is the code that I'm using for moving forward:

D3DXMATRIX matRot;

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

newX -= (elapsedTime * speed) * vecForward.x;
if (rotationY != 1.0f)
newY -= (elapsedTime * speed) * vecForward.y;
newZ -= (elapsedTime * speed) * vecForward.z;

How do I modify the above code to make the player move on the terrain normally, without flying?

I'm using Bullet Physics.

##### Share on other sites

Yep, that's typically what it looks like when you just move an object in two dimensions. In your case it appears like the player object moves along the (x,z) plane.

Try incorporating an alternative up vector besides (0,1,0) into your calculations, so the first push isn't straight away from the slope, but rather along the slope, then there will be less "falling", "skipping" or "flying" behavior. :)

##### Share on other sites

Tried to change the line:

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

To:

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


Solved the problem, but that doesn't seem to work correctly with other meshes (anything other than characters), should I use a different code for other meshes?

##### Share on other sites

By other meshes I assume you mean horses and vehicles, which are longer/wider than they are tall?

Basically you have to work at the four corners of the oriented bounding box and find the up vector based on that. Reimer Grootjans covers the algorithm in one of his XNA programming recipes.

http://shiba.hpe.sh.cn/jiaoyanzu/WULI/soft/XnaRecipes/XNARecipes.pdf

Section 4-17.

Correctly Tilt a Model Corresponding to the

Terrain Underneath

Edited by Steve_Segreto

1. 1
2. 2
3. 3
4. 4
5. 5

• 14
• 9
• 10
• 12
• 17
• ### Forum Statistics

• Total Topics
632909
• Total Posts
3009172
• ### Who's Online (See full list)

There are no registered users currently online

×