Sign in to follow this  
Medo Mex

Player Falling on Terrain Heights Instead of Moving

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:


D3DXMatrixRotationYawPitchRoll(&matRot, D3DXToRadian(rotationX), D3DXToRadian(rotationY), D3DXToRadian(rotationZ));

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 this post

Link to post
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 this post

Link to post
Share on other sites

Tried to change the line:


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



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 this post

Link to post
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.


Section 4-17.

Correctly Tilt a Model Corresponding to the

Terrain Underneath

Edited by Steve_Segreto

Share this post

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this